Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2248257rwl; Thu, 6 Apr 2023 07:46:39 -0700 (PDT) X-Google-Smtp-Source: AKy350aVahGeEQU2iaMPHjh0Ajh5pSgFEa5T6EH51RpgDT8+nyAMEoE3uMuXrpKqbqmDBFV60NwH X-Received: by 2002:a17:906:f1d9:b0:93d:bae1:ca9e with SMTP id gx25-20020a170906f1d900b0093dbae1ca9emr6986543ejb.25.1680792399116; Thu, 06 Apr 2023 07:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680792399; cv=none; d=google.com; s=arc-20160816; b=Lwk86+CMKFkBLu/kpyLVzXzYYawywAee+qcvWHdKS7yU5NirGniT7x4QIHhIzitMU4 u79ekVWJzwLoxEZrXu6v2z9LgdArKFBI2NDWTFD/LxFTjBafEgzTGbomFUk/I47Jn9e5 wGThRO1E8373NZBUYInSxuD3U+QNqaUysVGRknr1n+Gzy+hLDJsAnxoeme9kihae4fxa 81ceez+ZQ8xL/C+p+6MrX1kq7BkfGpPL9j0wIefg1YnVj0okQQMTl77ugCPSxFs+L8ci GLC/B0XkFpux0GmRNw9zX15NrjrjLAsRjcHXfR7wPbCUIK4dZTMlCCHQlYJElMh4qyHl YETA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=I0iWGy9sDLMNAMKNswk2ciZ3Lrwe+H+UTgUiyY4bepw=; b=O1Op/TZc7KM57px0YRm9VVl1nBQ9BCvbVz0nzEJDdusHK4O8+xLvhdyNP6LPsuecBM 4FZH2Ytf41B1VACnlYgx++9FTRKbcm0fLRcOy+ySzhvAfslhnKCAFvnRNIe2M1n2UcX2 2cM6OdZ0mSBuHbgp8XvT/A8fc+SLQ1bxPNdfadF9lXv21e3SgdPQIlyk/6O6xk3dKdkw FhTKP9ICn0fvauNAbNkVcnEbmBzMlsvM8CsaVFphHwIaAPtNhcWVWhYy0fgeDPKY5aFc QwcU7jLTXue3lywJYHt9JBWvBYfncSxk5eEmPmxxV+qTKQQiiXK91U8yZuGrgf3eFRF4 Rzeg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a17090614ca00b008de42a0a7a8si1230077ejc.186.2023.04.06.07.46.13; Thu, 06 Apr 2023 07:46:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239056AbjDFOnt (ORCPT + 99 others); Thu, 6 Apr 2023 10:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238669AbjDFOne (ORCPT ); Thu, 6 Apr 2023 10:43:34 -0400 Received: from frasgout11.his.huawei.com (frasgout11.his.huawei.com [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BF69A5F8; Thu, 6 Apr 2023 07:42:42 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4PskWP4spGz9xqnc; Thu, 6 Apr 2023 22:33:21 +0800 (CST) Received: from [10.48.151.63] (unknown [10.48.151.63]) by APP2 (Coremail) with SMTP id GxC2BwA3AFc62i5ki__8AQ--.42S2; Thu, 06 Apr 2023 15:42:13 +0100 (CET) Message-ID: <15d9dab3-379b-c62c-dd52-a810abe6985d@huaweicloud.com> Date: Thu, 6 Apr 2023 16:42:00 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH v1 2/2] swiotlb: Fix slot alignment checks To: Kelsey Steele , Petr Tesa????k Cc: Dexuan Cui , Dexuan-Linux Cui , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Konrad Rzeszutek Wilk , Jianxiong Gao , David Stevens , Joerg Roedel , "open list:DMA MAPPING HELPERS" , open list , Roberto Sassu , "Michael Kelley (LINUX)" , Tianyu Lan , "linux-hyperv@vger.kernel.org" References: <20230405064019.6258ebb3@meshulam.tesarici.cz> <20230405072801.05bb94ef@meshulam.tesarici.cz> <20230405075034.3c36bb77@meshulam.tesarici.cz> <20230406045204.GA20027@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Language: en-US From: Petr Tesarik In-Reply-To: <20230406045204.GA20027@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CM-TRANSID: GxC2BwA3AFc62i5ki__8AQ--.42S2 X-Coremail-Antispam: 1UD129KBjvJXoWxurW5GF4UZw1kCw1kZrWkZwb_yoW5GFWfpF WSya1qkF4DJry8tw12y3srta12q345Gr1UXr1rK34Skrn8KFn5JryUKrWj9asxKr4fWa10 vr4jqFW3tFy5JaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvIb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc7I2V7IY0VAS 07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c 02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_ WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7 CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF0xvEx4A2jsIE 14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x07UdxhLUUUUU= X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.2 required=5.0 tests=NICE_REPLY_A,SPF_HELO_NONE, SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 wrote: >> >>> On Wed, 5 Apr 2023 05:11:42 +0000 >>> Dexuan Cui wrote: >>> >>>>> From: Petr Tesa????k >>>>> 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