From patchwork Wed Feb 28 13:39:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 21089 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3350833dyb; Wed, 28 Feb 2024 05:39:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWitke+ly5rgnbz3g2PJF9kl9G8ooH7FL1xu3EZh4A9IuKdVFrTSyIhm1DWtdkep44NwohP9lgpJWm6vxN0LgdfiVbpGw== X-Google-Smtp-Source: AGHT+IFVIZW5GwGEVfeSwSBRvWkq4K7JlR8tqpnlggZdk2PkRr3wFghpLiMUAiOHcNtA5jvRxW4N X-Received: by 2002:a0c:e44d:0:b0:68f:5725:907c with SMTP id d13-20020a0ce44d000000b0068f5725907cmr4824011qvm.58.1709127596174; Wed, 28 Feb 2024 05:39:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709127596; cv=pass; d=google.com; s=arc-20160816; b=dVB8NhxqbUrmMMmu7UqqFtq2WZTeR5LzHCVSIqigqRXegY9OpjR4LXRuCDllUl2tNi HFbfcX8XbNTX+JuyRq14Ic/PIQP+YbV48JL89ZZ/RtdK+PbpEHU2GtQwPiabCLBz/OdO lfnTrIUEcDz1y00VzGO4D1Jz9exSYpU/jr9XhbaIwQyaejZ8I0VIPBcOPRvQQePCdmw1 KciN6T3/DUGUEUt/JCnmjHTMCUgz2j51p8d+O5BM4SL7E7y4LZUGc0o1kHkpDAqdlkE8 NQevmIAul/hrh4dx74XezKrj/9+FbWvpcxHkiVXRIn9UIcdfMrmtXQdozrs+KCBr4s5c d+bA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=iaxJXiyqojhw1e/6wwArxR90FFLV2Ab4/bX8whTZL+E=; fh=E8F5/vp/nAcPVJWJwVt5RE8c2HME7kVqVeSMFxe8huE=; b=D9n9p5qwlD4Rh/S8uPzijOpDTqL4g16+qD1VHfbOFgew0wwVWcjVPx2vyndyqmhS3E D7TnTZtNBwa17w0/YEt0ZnsrY115jGKiHx3vyjrHz6+5TVakkvrPqhYVKqbUJDhyQmlP 62V2qwTMU3hHLyretTvnBdB4EwSFhuyc0GfhQUPckm3eKFkpo70ZHBdXIMTQP8R3Bog9 LPdt5KMOGLcP0ZKNIom/2+FSRq8Z/pYT9o2RVd3AI3vQLWRNOzeOS5MayHymKu0UWwIC /nt/loKmiu4UuLgF6rzCqj5yaYSIb2l6QNrh1u5UCJfrucyrOIWqoVVJprUd+U+61jVm 9pIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cW0JH05C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-85108-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85108-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o2-20020ad45c82000000b0068f4b29a51csi10040676qvh.286.2024.02.28.05.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 05:39:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85108-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cW0JH05C; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-85108-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85108-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id F014D1C222E5 for ; Wed, 28 Feb 2024 13:39:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BBC1F14F9FA; Wed, 28 Feb 2024 13:39:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cW0JH05C" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1876614AD07; Wed, 28 Feb 2024 13:39:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709127577; cv=none; b=krx7+4sGD7piDDlwCy+9YJB0I52fRhYujwdyLZqzrr9mjnyix6flJeghiEXP09BscxrtLwfUaS2q7nIrKfZhONr/mJ6obctoEtM2z+U9yWYgB2IdvHcgFcWNME1+w4MoCH7owCTghoN9z0RNxBNpK5dhhVbmOlFb5xqvLOpMPy0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709127577; c=relaxed/simple; bh=9M5IeUXf3IQoeSYqVlOLU709MVkE93Tw2opRABbT/bs=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=C9drTXMmEcJJtB2fvPrmZM+1OXYsm5S4BkjjOyht7sXd1iDjzbvwIjO6Q7oAulIa7HUdJdVx11iWkeyrz+w1zT5BD2YAg1M33jFbDi0B+H+onIYMT4o3FaT/ywQ+n5QCTMwSmiQw8gSIJy0dD9L8A7s82fjMNio5XxzLtWD1Tn0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cW0JH05C; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8FEE5C433F1; Wed, 28 Feb 2024 13:39:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709127576; bh=9M5IeUXf3IQoeSYqVlOLU709MVkE93Tw2opRABbT/bs=; h=From:To:Cc:Subject:Date:From; b=cW0JH05Cslh9hwgukH/5vLo/F5orXfPEP+8a7EHwdeehPxmWkap/0tEVqXTtv9pns 98mvJ19iHQ/ltGsOEQvIReTkQxhbSKJmeOXc6BYj/A0X8xuNVtf2KDhgssuKh0Qp+t 4sYuVtBBveyEYvccu9XT4erREGsWwxnNUF84TgA5D78cPy/2iOg1K5oCeYyMjPDgSr bg3JJ3M2mcYK7mqzts4irrJpnN6IaHNs8VUZo2CVsIxwfVamxI39kAWRXSOUGy7RWx CJ5KKhPOY/9kJhGIvggJHF2HGI5k+4/w+9Av1vc3zjfw6otCXmNy5rQ50rRXKbuXlH b/TUkZ73XzlCQ== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, Will Deacon , iommu@lists.linux.dev, Christoph Hellwig , Marek Szyprowski , Robin Murphy , Petr Tesarik , Dexuan Cui , Nicolin Chen , Michael Kelley Subject: [PATCH v5 0/6] Fix double allocation in swiotlb_alloc() Date: Wed, 28 Feb 2024 13:39:24 +0000 Message-Id: <20240228133930.15400-1-will@kernel.org> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792150178496915889 X-GMAIL-MSGID: 1792150178496915889 Hi all, This is version five of the patches which I previously posted at: v1: https://lore.kernel.org/r/20240126151956.10014-1-will@kernel.org v2: https://lore.kernel.org/r/20240131122543.14791-1-will@kernel.org v3: https://lore.kernel.org/r/20240205190127.20685-1-will@kernel.org v4: https://lore.kernel.org/r/20240221113504.7161-1-will@kernel.org Cheers again to everybody who helped to review and test the last version. Changes since v4 include: - Remove unnecessary 'is_swiotlb_active()' from patch 5. Nicolin: I didn't add your Tested-by because of this, so if you can take it for another spin, that would be fantastic. - New patch removing redundant stride adjustment for allocations of PAGE_SIZE or more. - Commit message tweaks and addition of tags from reviewers and testers. The final patch is a cleanup, so I'm happy to post it again after the merge window if it doesn't make it this time around. The rest are fixes and, even though patch five doesn't solve the general problem, it's sufficient to fix NVME for Nicolin and is definitely an improvement over what we currently have. Thanks, Will Cc: iommu@lists.linux.dev Cc: Christoph Hellwig Cc: Marek Szyprowski Cc: Robin Murphy Cc: Petr Tesarik Cc: Dexuan Cui Cc: Nicolin Chen Cc: Michael Kelley --->8 Nicolin Chen (1): iommu/dma: Force swiotlb_max_mapping_size on an untrusted device Will Deacon (5): swiotlb: Fix double-allocation of slots due to broken alignment handling swiotlb: Enforce page alignment in swiotlb_alloc() swiotlb: Honour dma_alloc_coherent() alignment in swiotlb_alloc() swiotlb: Fix alignment checks when both allocation and DMA masks are present swiotlb: Remove pointless stride adjustment for allocations >= PAGE_SIZE drivers/iommu/dma-iommu.c | 9 +++++++++ kernel/dma/swiotlb.c | 36 +++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 13 deletions(-)