Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2512001rwb; Mon, 3 Oct 2022 01:39:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7xtnNE9g1DP/wCsj9+zBNx3ZDEcR6eUiOLSmOlK6Vt70LkdQ8eOkgS6o4g24s9rfxc9Olo X-Received: by 2002:a17:90a:4d8d:b0:20a:85c0:1f2c with SMTP id m13-20020a17090a4d8d00b0020a85c01f2cmr7455880pjh.43.1664786380218; Mon, 03 Oct 2022 01:39:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664786380; cv=none; d=google.com; s=arc-20160816; b=Kff27U2adxGklO/uBYVlHuWrlXfJZ1wGyTPyz1g9kI/dPJ4L5LHoAyfnAzAjVboEU9 ZuyKc6Mn4DdTpzSzp97NTGq5fGjTbOMnoixkTh/J6kto7qj7lSO2JGtJ1NXIU34hAoQJ /TGc6lrz/yM0cJnqqi8uyWW5CB+v//TbxrEbM7UM2pgZupVb085rhVp303vnCe2naJtb veqYDzTAb4mKbVm/2yraA7LZrtSUxfv/Nzt8ZhuKYYQau7PGhsQEDRgwtNm/R0NNwUQP 0kD7MCGtuJO1F5RZDqoHW+3fqFHQulYLKyq5Ec0JD/yji6YV/3p2VK4KRvCToyGT7sWJ 5NnA== 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=U2grLi+IgFNGvDx+O+V5VRdLGg7NifMh8iF6nsNW/Cs=; b=sVZ4ETrfS6rvLB9xgYHr6pCDOzqEDiLNpN9x7dNXQ4UY7CPnlzeRdzCx3Zqv50FDcA LLLYsRa71ALSOQ3EAvhx54KT5E/lPCrXsFDsLnM/HM9sf9lu1m3cP72vdrUMll87b0Ee vW1/HPKO3KNQ6XFxyZjIoAtygeuzr6QWOQIsgJ752tMfa9BV32afgb0sKsgJc5tuoudY ZsUgUDxokOAJDo8qWtspoNyNxH+ZwlxDJ8/o70zEjQOq8EhNaRkiQGD6f2N8B8DkGEDi 05PrncjQXRIJcxW9IZyv0TJEtv1uAZLU7/mn00x1D0PFjVa9HLSfrHvMFVw9IOkKwaIF Ydhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=helOcA+7; 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 p5-20020a170902bd0500b0017a0582050esi9230879pls.59.2022.10.03.01.39.28; Mon, 03 Oct 2022 01:39:40 -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=helOcA+7; 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 S231290AbiJCH3w (ORCPT + 99 others); Mon, 3 Oct 2022 03:29:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbiJCH2m (ORCPT ); Mon, 3 Oct 2022 03:28:42 -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 80B7E657A; Mon, 3 Oct 2022 00:19:42 -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 34839B80E81; Mon, 3 Oct 2022 07:18:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CCFFC433C1; Mon, 3 Oct 2022 07:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781486; bh=16kv6EE0M1hk+TTangBFeVgAF2owVYJ/Tjd+2RcjAks=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=helOcA+7QYg70lyd3fTjN13WqAZH4+Pneg4myPPiAOn6X8Yse15gaaHbVf44XP8Kp SIJf+ug2hXZTk41UKEP8vIer8TBslav5B5qj0jB/VwY8zum5yuq2VXldBbS6O0NWpq f1lbETIU1BzYevkD/knssPProGM5AYdA/z+u1Fjo= 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.15 38/83] swiotlb: max mapping size takes min align mask into account Date: Mon, 3 Oct 2022 09:11:03 +0200 Message-Id: <20221003070722.955669891@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@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 @@ -709,7 +709,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(struct device *dev)