lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Wed, 2 Feb 2022 22:36:35 +0800
From:   Tianyu Lan <ltykernel@...il.com>
To:     Christoph Hellwig <hch@...radead.org>
Cc:     kys@...rosoft.com, haiyangz@...rosoft.com, sthemmin@...rosoft.com,
        wei.liu@...nel.org, decui@...rosoft.com, tglx@...utronix.de,
        mingo@...hat.com, bp@...en8.de, dave.hansen@...ux.intel.com,
        x86@...nel.org, hpa@...or.com, m.szyprowski@...sung.com,
        robin.murphy@....com, michael.h.kelley@...rosoft.com,
        Tianyu Lan <Tianyu.Lan@...rosoft.com>,
        iommu@...ts.linux-foundation.org, linux-hyperv@...r.kernel.org,
        linux-kernel@...r.kernel.org, vkuznets@...hat.com,
        brijesh.singh@....com, konrad.wilk@...cle.com, hch@....de,
        parri.andrea@...il.com, thomas.lendacky@....com
Subject: Re: [PATCH 0/2] x86/hyperv/Swiotlb: Add swiotlb_alloc_from_low_pages
 switch

On 2/2/2022 4:12 PM, Christoph Hellwig wrote:
> I think this interface is a little too hacky.  In the end all the
> non-trusted hypervisor schemes (including the per-device swiotlb one)
> can allocate the memory from everywhere and want for force use of
> swiotlb.  I think we need some kind of proper interface for that instead
> of setting all kinds of global variables.

Hi Christoph:
      Thanks for your review. I draft the following patch to export a
interface swiotlb_set_alloc_from_low_pages(). Could you have a look
whether this looks good for you.

diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index f6c3638255d5..2b4f92668bc7 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -39,6 +39,7 @@ enum swiotlb_force {
  extern void swiotlb_init(int verbose);
  int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  unsigned long swiotlb_size_or_default(void);
+void swiotlb_set_alloc_from_low_pages(bool low);
  extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  extern int swiotlb_late_init_with_default_size(size_t default_size);
  extern void __init swiotlb_update_mem_attributes(void);
diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index f1e7ea160b43..62bf8b5cc3e4 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -73,6 +73,8 @@ enum swiotlb_force swiotlb_force;

  struct io_tlb_mem io_tlb_default_mem;

+static bool swiotlb_alloc_from_low_pages = true;
+
  phys_addr_t swiotlb_unencrypted_base;

  /*
@@ -116,6 +118,11 @@ void swiotlb_set_max_segment(unsigned int val)
                 max_segment = rounddown(val, PAGE_SIZE);
  }

+void swiotlb_set_alloc_from_low_pages(bool low)
+{
+       swiotlb_alloc_from_low_pages = low;
+}
+
  unsigned long swiotlb_size_or_default(void)
  {
         return default_nslabs << IO_TLB_SHIFT;
@@ -284,8 +291,15 @@ swiotlb_init(int verbose)
         if (swiotlb_force == SWIOTLB_NO_FORCE)
                 return;

-       /* Get IO TLB memory from the low pages */
-       tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       /*
+        * Get IO TLB memory from the low pages if 
swiotlb_alloc_from_low_pages
+        * is set.
+        */
+       if (swiotlb_alloc_from_low_pages)
+               tlb = memblock_alloc_low(bytes, PAGE_SIZE);
+       else
+               tlb = memblock_alloc(bytes, PAGE_SIZE);
+
         if (!tlb)
                 goto fail;
         if (swiotlb_init_with_tbl(tlb, default_nslabs, verbose))


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ