Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp9252lqh; Fri, 3 May 2024 11:37:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUP1lFvTzNR1RYNNv9YjeQ5OzZwcvC7ykUfLY2lSdDGPlmxOi5QaUGWugfxokM6LBkZTQr1JaSoVi6ew4AnXIcOTQhRcH2UmXcrgAgC3w== X-Google-Smtp-Source: AGHT+IGEvZKUTR+NPi6USmsWhSReP0Ohm/1uHfI8UyN40SOCSy7R+KLXGvPjIyitKy3GRnbY4v9i X-Received: by 2002:a05:620a:284b:b0:792:5f82:30f with SMTP id h11-20020a05620a284b00b007925f82030fmr3699695qkp.51.1714761479473; Fri, 03 May 2024 11:37:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714761479; cv=pass; d=google.com; s=arc-20160816; b=O81hQutrn5zTJGv7Cxo1Co+0VNyxWlTLx4s9iqHxzWEdt4aUXCB2/vcqVU/tReUTPE itTDnbAbv8sp2ehBcbCmh/mADSljaQxrBz8+Ns6yO1nNcf19E1vk+ODMcUfldBNWE2pU OxbgJLH/iR0GCHGG6kHNHgfccwCow6qTHbNfmovIbK4U1gqt8tVLqs6iKSsnmdaqI5Uf i6+kHK5PPGydnA8g3HJ5V9AWTvdC63Xb5TuU59bjzMnD5eDOztNjSrJ3WdOd/8pUisM3 sa6DRtnCAcIOVLh9KbrcxOP3UgCa89VOXTRZks3f3WaxbzmcHaFySwy8MtFV1dxnsDb8 MGDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=dnbX50dR3baSwjlitnZlT2KQP1Bjq1hEVDevUqr+0/8=; fh=c6K0GmEeK63HSIDs8AGL6tmGaNSXSwtcdcCILIHvCW0=; b=FBTT7wxb2Fb8FPCrEMvGpueofIMEEvoynYhdbK7/so8DgvTHgWR9gNB+NuZG7p8APw v1IfJzy57uCb6Es639Szwgc6xXDuAaCMpltNArNpnlvSvticTXkcAasz3GuU2BYxxJFy B9GUq6KJp76zdUrV9an3H6vW29AFw5XJhv8PPsIgJo6uPF/WwTEa2kXglUzxHqkdJuZw ut58osrEJZqXpJ/BXcS0AZdPbijn7fxCIffYKG4pQDp6D2gnuGHfLZozmaOnQXV6d2if uS20+0ZNHEx07LeoMKBeWPM5O0a8bGuiX0nbDtXCSgYVqYC/O1BpeXcTty9Ew8ysIlyc 8pxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yEKFjTt/"; arc=pass (i=1 spf=pass spfdomain=flex--tjmercier.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-168074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ea19-20020a05620a489300b00790f46177adsi4047302qkb.274.2024.05.03.11.37.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 11:37:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yEKFjTt/"; arc=pass (i=1 spf=pass spfdomain=flex--tjmercier.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-168074-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168074-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 39B871C21C34 for ; Fri, 3 May 2024 18:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AF9312F385; Fri, 3 May 2024 18:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yEKFjTt/" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3013A1CD1F for ; Fri, 3 May 2024 18:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714761440; cv=none; b=fGs2I223Kj2/r+2AHL3lhvR5IIEL+PKJkTwGo0ARuewcba0Mqb9PvJtKgdDQ7YwE8Xe+qw3xu0mX+KLwsJaeJLaXBSF9J35kLfi8alZ7mG7jnGjbJOpRzTgVFQjQK8zttARsjx9lDX4kcilirdr5XEp18LqOrHJgWWw76AU3IT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714761440; c=relaxed/simple; bh=wm5pk9S0/JQcuHXC+N1ugdSHVS+48gum9vVTthDqGHE=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=LK1VT+l+8207ubSAB4nckqcONg8EYBdED6GGv8wKi8QSFbcaxJImZPHpGfv6556oGKCxLfkREDdwi2w1lpBqgCKX099DxwaO3FeAKHck9lnrJ9+9grU9ICTAkz6ftGW3Yk4k00iBoC7q6vNvcL2vdWhro9M+FFcqDE4N6i/pTuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yEKFjTt/; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de60cd96bf3so11392276.0 for ; Fri, 03 May 2024 11:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714761438; x=1715366238; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=dnbX50dR3baSwjlitnZlT2KQP1Bjq1hEVDevUqr+0/8=; b=yEKFjTt/QInii+9ewC1xT/FkuV5uef/g3PPIUNc2dZiBgOAvUfcXwpNuHjJqFtN02q AcM+lL89z2KaUp46Mbv3JZ5D6uSyvBIxNgX4JTCIOMEGEwDYUEl7INfag6TbZlqidmR+ vwggkYbzbSrlgPXhh0mEzo2SwFdoG6sqj9uhrPnq9G+FXtkCn+nsMoJmgZ3IyswqVehz CdwgRqPEOwnoxH8s0hrYAw+YjeplLxoDfQp5SsBCc9FH+gyCPh61solB/pRGtu54r7HE Vwe0pYHLEMbvhRZqZ/fS8gfEHhwhlXBJQjhimsaI3uNgOP7cyHwEk/aSCmsZcN6ybTYq OXVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714761438; x=1715366238; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=dnbX50dR3baSwjlitnZlT2KQP1Bjq1hEVDevUqr+0/8=; b=TY4VliC3QSufCy07ljBL+KteVJ4Fmv+0sNvOPKdZ6AXqr2V/CU8VYK+DLb6cTzYpo2 bTKcLtwlAFmZkhoHZS21CrrUHs0FCYsPgNG2ABGs1wle692ppvsQy2ce82Wa2Y/EgFq3 dLcjdXzIDCiHLvVC9b768xS6LdiYfELvrQEAgSICihgr/s124ykaZOnMJDQMLGl2l3Gv VfnAiRNE+hpRZ0H4Vtw27a9dtyIz4llzGm1aYMOlXsv6f4pcXhY7BY/D6z7mB3yRazn4 /Vxvrr7Usn3WEvX8H5BsH0hu995Fs/Bw/UAOUOVGAxsMZCUByB3B/y5kLF0z4+DmOBPw x5Zw== X-Forwarded-Encrypted: i=1; AJvYcCX9Dmj91bgJgZ2rc6Rtosp0DnmExHF57vreQ0YBT4Zr/W2084YVgnexfHqKfTBIpgB2wvp5ETUXS7IJMoyF987t/DP8f9vxI94wSRMY X-Gm-Message-State: AOJu0YyNqXzIiy53LZEXdGVSExhPTbB4FEb464AlOCzsU7V8Mf59Z1HM l8zBRUyQZsITiQrrQs2lU+jgb4UJblx3H2lPYmvws93EAIX5YrQT0PF2cWTmynXIF3btdb4ry7g FgfvpehmI2i1PAg== X-Received: from tj-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5683]) (user=tjmercier job=sendgmr) by 2002:a05:6902:102a:b0:dd9:2782:d1c6 with SMTP id x10-20020a056902102a00b00dd92782d1c6mr1222431ybt.1.1714761438256; Fri, 03 May 2024 11:37:18 -0700 (PDT) Date: Fri, 3 May 2024 18:37:12 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Message-ID: <20240503183713.1557480-1-tjmercier@google.com> Subject: [PATCH] dma-direct: Set SG_DMA_SWIOTLB flag for dma-direct From: "T.J. Mercier" To: tjmercier@google.com, Christoph Hellwig , Marek Szyprowski , Robin Murphy Cc: isaacmanjarres@google.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" As of commit 861370f49ce4 ("iommu/dma: force bouncing if the size is not cacheline-aligned") sg_dma_mark_swiotlb is called when dma_map_sgtable takes the IOMMU path and uses SWIOTLB for some portion of a scatterlist. It is never set for the direct path, so drivers cannot always rely on sg_dma_is_swiotlb to return correctly after calling dma_map_sgtable. Fix this by calling sg_dma_mark_swiotlb in the direct path like it is in the IOMMU path. Signed-off-by: T.J. Mercier --- kernel/dma/direct.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 4d543b1e9d57..52f0dcb25ca2 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include "direct.h" /* @@ -497,6 +497,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, goto out_unmap; } sg_dma_len(sg) = sg->length; + if (is_swiotlb_buffer(dev, dma_to_phys(dev, sg->dma_address))) + sg_dma_mark_swiotlb(sg); } return nents; -- 2.45.0.rc1.225.g2a3ae87e7f-goog