Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2527101rwb; Mon, 3 Oct 2022 02:00:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5zd2I6GjyhXyPwlFgr0Te1LYr433qwPICiNNcqGb7W+/RAQwexE5oGKBu0yIOcqS6xe3pN X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr18229212edb.347.1664787613917; Mon, 03 Oct 2022 02:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664787613; cv=none; d=google.com; s=arc-20160816; b=rXe9RyyxFWOmbIkVC8A2asLhUktgujMidGKgf3DuIqMZXirNKQS4eKDyXNk7REAO+x MsiqVRFOqeT2GM25XqzANdx+WhzVOO4mC0S/rEUbOOkmpCGrViqT2qxPGxO/IhSpClcH JmN6HKa9wmaTKD5MsjXkXWc4kaC2oEX72Go+70rjpagk+CJ+2lyQSiipmpjDQpFAi3oC r3OJate9imuVp4x6ctAFW9Oqqf3DO3aNO7UFPeaTbFcVQ6hhY85xoTpfk9B9Hd3IPzX4 PdYCjYHBwn7Yd9TuExT0QzITqGOR3HObQtH/dp9AyvyBTEdLpj/HI8Wnt87XiRR/tENM veEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uJrU1EofFOSibW6KF6GrFo+Vo+RE8LRi/ymna5Z28ks=; b=H8dC46x6qm4U51ewbVln9lmFFO32Uxzkx7FmAEEOybPD27hKW+Fy3OsDJ6eeH36A5D vVm78RP85mVApkxcM2zzQeanY2oegVqrtIEMVOKevtRYWM12TEnTFxFHP1/IVuNKrwbI 90BrW2dVxQNroGWmM90tUW4i6Qrq1//BeD+UIStS8hlz7gX5jUNLRY0I6SM+37GenmGh xPPdA1kERWDO0lxi0fNEkP7bmjzJbsOp7RlrCMQIcDO565EXC2waweYz6I/zS4+V9N9K 0kJFiTFn0J1gP08MH//kMMKQ9D2QeO9HiPo/Wa1MgVSKbZ3RPlOpBXrrLI28y0XiuVIh Zl9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E0cDIkyW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c16-20020a05640227d000b0044900e60983si8257758ede.541.2022.10.03.01.59.48; Mon, 03 Oct 2022 02:00:13 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E0cDIkyW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbiJCHhy (ORCPT + 99 others); Mon, 3 Oct 2022 03:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231650AbiJCHgI (ORCPT ); Mon, 3 Oct 2022 03:36:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D1535302F; Mon, 3 Oct 2022 00:22:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 11ECEB8058E; Mon, 3 Oct 2022 07:22:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6ED1CC433C1; Mon, 3 Oct 2022 07:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781740; bh=hVdb9qmX4fLeNhfN+5f0mEz99rs8emTUuRZSjrCX1U0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E0cDIkyWquY46vXzP9+Lwc9PLFSQzI6G40eCaQHo+lQF1DG6UOW3QMhjR5ss1Q0g0 6IrffqmoJUaZYuiHeh8wB4wMCUfKqFPon0DrMudIZoxt8mjFqPWL95Qn4lYXV3VrEj lSzk5FwVMkinXh392ghLh+xIKK8Ti/JaS+8OnxHU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tianyu Lan , Christoph Hellwig , Rishabh Bhatnagar Subject: [PATCH 5.10 29/52] swiotlb: max mapping size takes min align mask into account Date: Mon, 3 Oct 2022 09:11:36 +0200 Message-Id: <20221003070719.596805486@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070718.687440096@linuxfoundation.org> References: <20221003070718.687440096@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 From: Tianyu Lan commit 82806744fd7dde603b64c151eeddaa4ee62193fd upstream. swiotlb_find_slots() skips slots according to io tlb aligned mask calculated from min aligned mask and original physical address offset. This affects max mapping size. The mapping size can't achieve the IO_TLB_SEGSIZE * IO_TLB_SIZE when original offset is non-zero. This will cause system boot up failure in Hyper-V Isolation VM where swiotlb force is enabled. Scsi layer use return value of dma_max_mapping_size() to set max segment size and it finally calls swiotlb_max_mapping_size(). Hyper-V storage driver sets min align mask to 4k - 1. Scsi layer may pass 256k length of request buffer with 0~4k offset and Hyper-V storage driver can't get swiotlb bounce buffer via DMA API. Swiotlb_find_slots() can't find 256k length bounce buffer with offset. Make swiotlb_max_mapping _size() take min align mask into account. Signed-off-by: Tianyu Lan Signed-off-by: Christoph Hellwig Signed-off-by: Rishabh Bhatnagar Signed-off-by: Greg Kroah-Hartman --- kernel/dma/swiotlb.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -734,7 +734,18 @@ dma_addr_t swiotlb_map(struct device *de size_t swiotlb_max_mapping_size(struct device *dev) { - return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE; + int min_align_mask = dma_get_min_align_mask(dev); + int min_align = 0; + + /* + * swiotlb_find_slots() skips slots according to + * min align mask. This affects max mapping size. + * Take it into acount here. + */ + if (min_align_mask) + min_align = roundup(min_align_mask, IO_TLB_SIZE); + + return ((size_t)IO_TLB_SIZE) * IO_TLB_SEGSIZE - min_align; } bool is_swiotlb_active(void)