linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Tesarik <petr.tesarik.ext@huawei.com>
To: Kelsey Steele <kelseysteele@linux.microsoft.com>
Cc: Petr Tesa????k <petr@tesarici.cz>,
	Dexuan Cui <decui@microsoft.com>,
	Dexuan-Linux Cui <dexuan.linux@gmail.com>,
	Christoph Hellwig <hch@lst.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Jianxiong Gao <jxgao@google.com>,
	David Stevens <stevensd@chromium.org>,
	Joerg Roedel <jroedel@suse.de>,
	"open list:DMA MAPPING HELPERS" <iommu@lists.linux.dev>,
	open list <linux-kernel@vger.kernel.org>,
	Roberto Sassu <roberto.sassu@huawei.com>,
	"Michael Kelley (LINUX)" <mikelley@microsoft.com>,
	Tianyu Lan <Tianyu.Lan@microsoft.com>,
	"linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>
Subject: Re: [PATCH v1 2/2] swiotlb: Fix slot alignment checks
Date: Tue, 11 Apr 2023 17:46:36 +0200	[thread overview]
Message-ID: <7065e2ee-3de4-f54d-04a9-12bfcd3a9481@huawei.com> (raw)
In-Reply-To: <20230407041304.GA28729@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>

On 4/7/2023 6:13 AM, Kelsey Steele wrote:
> On Thu, Apr 06, 2023 at 04:42:00PM +0200, Petr Tesarik wrote:
>> Hi Kelsey,
>>
>> On 4/6/2023 6:52 AM, Kelsey Steele wrote:
>>> On Wed, Apr 05, 2023 at 07:50:34AM +0200, Petr Tesa????k wrote:
>>>> On Wed, 5 Apr 2023 07:32:06 +0200
>>>> Petr Tesa????k <petr@tesarici.cz> wrote:
>>>>
>>>>> On Wed, 5 Apr 2023 05:11:42 +0000
>>>>> Dexuan Cui <decui@microsoft.com> wrote:
>>>>>
>>>>>>> From: Petr Tesa????k <petr@tesarici.cz>
>>>>>>> Sent: Tuesday, April 4, 2023 9:40 PM    
>>>>>>>>> ...
>>>>>>>>> Hi Petr, this patch has gone into the mainline:
>>>>>>>>> 0eee5ae10256 ("swiotlb: fix slot alignment checks")
>>>>>>>>>
>>>>>>>>> Somehow it breaks Linux VMs on Hyper-V: a regular VM with
>>>>>>>>> swiotlb=force or a confidential VM (which uses swiotlb) fails to boot.
>>>>>>>>> If I revert this patch, everything works fine.  
>>>>>>>>
>>>>>>>> The log is pasted below. Looks like the SCSI driver hv_storvsc fails to
>>>>>>>> detect the disk capacity:    
>>>>>>>
>>>>>>> The first thing I can imagine is that there are in fact no (free) slots
>>>>>>> in the SWIOTLB which match the alignment constraints, so the map
>>>>>>> operation fails. However, this would result in a "swiotlb buffer is
>>>>>>> full" message in the log, and I can see no such message in the log
>>>>>>> excerpt you have posted.
>>>>>>>
>>>>>>> Please, can you check if there are any "swiotlb" messages preceding the
>>>>>>> first error message?
>>>>>>>
>>>>>>> Petr T    
>>>>>>
>>>>>> There is no "swiotlb buffer is full" error.
>>>>>>
>>>>>> The hv_storvsc driver (drivers/scsi/storvsc_drv.c) calls scsi_dma_map(),
>>>>>> which doesn't return -ENOMEM when the failure happens.  
>>>>>
>>>>> I see...
>>>>>
>>>>> Argh, you're right. This is a braino. The alignment mask is in fact an
>>>>> INVERTED mask, i.e. it masks off bits that are not relevant for the
>>>>> alignment. The more strict alignment needed the more bits must be set,
>>>>> so the individual alignment constraints must be combined with an OR
>>>>> instead of an AND.
>>>>>
>>>>> Can you apply the following change and check if it fixes the issue?
>>>>
>>>> Actually, this will not work either. The mask is used to mask off both
>>>> high address bits and low address bits (below swiotlb slot granularity).
>>>>
>>>> What should help is this:
>>>>
>>>
>>> Hi Petr, 
>>>
>>> The suggested fix on this patch boots for me and initially looks ok,
>>> though when I start to use git commands I get flooded with "swiotlb
>>> buffer is full" messages and my session becomes unusable. This is on WSL
>>> which uses Hyper-V.
>>
>> Roberto noticed that my initial quick fix left iotlb_align_mask
>> uninitialized. As a result, high address bits are set randomly, and if
>> they do not match actual swiotlb addresses, allocations may fail with
>> "swiotlb buffer is full". I fixed it in the patch that I have just posted.
>>
>> HTH
>> Petr T
> 
> I pulled the patches from dma-mapping after your fix got applied and
> everything appears ok and goes back to the way it was; so no other
> errors to report. :) Unfortunately still getting the "swiotlb buffer is
> full" messages during kernel builds, though that was happening before
> your patches hit.
> 
> Thanks so much, Petr!

Sorry for breaking it in the first place. But the story also tells us
that some drivers do not really need as strict alignment as they
request, otherwise the kernel would have failed my smoke-testing.

Petr T


  reply	other threads:[~2023-04-11 15:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-21  8:31 [PATCH v1 0/2] swiotlb: Cleanup and alignment fix Petr Tesarik
2023-03-21  8:31 ` [PATCH v1 1/2] swiotlb: Use wrap_area_index() instead of open-coding it Petr Tesarik
2023-03-21  8:31 ` [PATCH v1 2/2] swiotlb: Fix slot alignment checks Petr Tesarik
2023-04-04 19:55   ` Dexuan-Linux Cui
2023-04-04 20:11     ` Dexuan Cui
2023-04-05  4:40       ` Petr Tesařík
2023-04-05  5:11         ` Dexuan Cui
2023-04-05  5:32           ` Petr Tesařík
2023-04-05  5:50             ` Petr Tesařík
2023-04-05  6:00               ` Dexuan Cui
2023-04-05  6:07                 ` Petr Tesařík
2023-04-05  6:34                   ` Dexuan Cui
2023-04-06  4:52               ` Kelsey Steele
2023-04-06 14:42                 ` Petr Tesarik
2023-04-07  4:13                   ` Kelsey Steele
2023-04-11 15:46                     ` Petr Tesarik [this message]
2023-04-05 12:24     ` Linux regression tracking #adding (Thorsten Leemhuis)
2023-03-22  8:05 ` [PATCH v1 0/2] swiotlb: Cleanup and alignment fix Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7065e2ee-3de4-f54d-04a9-12bfcd3a9481@huawei.com \
    --to=petr.tesarik.ext@huawei.com \
    --cc=Tianyu.Lan@microsoft.com \
    --cc=decui@microsoft.com \
    --cc=dexuan.linux@gmail.com \
    --cc=hch@lst.de \
    --cc=iommu@lists.linux.dev \
    --cc=jroedel@suse.de \
    --cc=jxgao@google.com \
    --cc=kelseysteele@linux.microsoft.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mikelley@microsoft.com \
    --cc=petr@tesarici.cz \
    --cc=roberto.sassu@huawei.com \
    --cc=robin.murphy@arm.com \
    --cc=stevensd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).