From patchwork Mon Apr 5 21:02:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA387C43461 for ; Mon, 5 Apr 2021 21:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFB3A6044F for ; Mon, 5 Apr 2021 21:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241213AbhDEVDJ (ORCPT ); Mon, 5 Apr 2021 17:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235284AbhDEVDG (ORCPT ); Mon, 5 Apr 2021 17:03:06 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E42CC061756 for ; Mon, 5 Apr 2021 14:02:59 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id s23so1712982plp.1 for ; Mon, 05 Apr 2021 14:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=PmrHGer98y5GPth22DEOJMU23+DTwZMIhPbqhMPinKg=; b=JV9u/4blSyno23H7hLGTcfF+ixk3hmvvdA0SlzoSjs65mWQPkJps7ctX/bsSAUsqzH sOplfi3KyEyX5+sfdSXVjwJlb0OANxAREZI7g9RtlcDlEX9vEuGafR5SvDjlw+U//U5J lqNF4SU0OAEjM1DWj3OxW/suryxoxR/JpetCAh8asj1YVA2iamRT8o4CotYcQEDige3P arzClj/gz3kC3/Wf+IiVjhGuY6cQe/Tg8V4sD/DeRGfY05WReTZ8f+VsFR7QisqkEYia EdAEzaQdhJ79ZvD/n/The4gMRiSGi6HvO86qGZac1ryHSZyydS0+j0xWpILhuOSNt8YG 3/fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PmrHGer98y5GPth22DEOJMU23+DTwZMIhPbqhMPinKg=; b=moLP5kuaBNf35gTxnudjRj1w1vOX7M9/UNjOMVkDqYug2EBkiR6tPYXzP8XqSn6SMV sHHsoVYKV2KaUYFAgplYICMcRZ1bgVSVydHQfs1SbKXvsU7mjuX8W4q/GOASwbkV1r1V K9JdAn4SjQq4heih4QwA06aZWpSMcnM/Pw0whE1QCi77l0mdxa5Rf73BfJYXN3j8+gai OjFDOF14zfylSFKZGDJz1gUXDv8jKarBhrEZRI9LhFGO8h2NmOkSwbFoC0FXotODISFo CVxUy5XcEpxbrOk8LWR9H+oSXzzoxwneiwmGklpf9YrPr2P1arWdkewmRUbr/JXQq64l sBRA== X-Gm-Message-State: AOAM532As49dq/Cp93qE7HEXKZ+VOKd3mMlzaybNv7FMx/q2nHNetA1W OAUpZtpc0PhLdQ+PrW5L7BaJIFvO3VxbODWknyp+dCfG1I5/NXoq1E52OC4kLJwvdVmkNiUgpHq d0Cj85q0gxFc39xkR9ATYxLCQL41rsRyz58ZY/805AkjOZvoCrmQe9K9gN+0= X-Google-Smtp-Source: ABdhPJxkRtR8ycjcJ9yB6QK0/WKHgNLbbJs9pVG/KHAgo1bA6rD2YKO703fUk70Wf3Zo/8r+PdnUPjtDgQ== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:aa7:8498:0:b029:1f6:8a25:7ade with SMTP id u24-20020aa784980000b02901f68a257ademr24789415pfn.76.1617656579044; Mon, 05 Apr 2021 14:02:59 -0700 (PDT) Date: Mon, 5 Apr 2021 21:02:24 +0000 In-Reply-To: <20210405210230.1707074-1-jxgao@google.com> Message-Id: <20210405210230.1707074-3-jxgao@google.com> Mime-Version: 1.0 References: <20210405210230.1707074-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH v5.10 2/8] swiotlb: factor out an io_tlb_offset helper From: Jianxiong Gao To: stable@vger.kernel.org Cc: Jianxiong Gao , Christoph Hellwig Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoph Hellwig 'commit c7fbeca757fe ("swiotlb: factor out an io_tlb_offset helper")' Replace the very genericly named OFFSET macro with a little inline helper that hardcodes the alignment to the only value ever passed. Signed-off-by: Christoph Hellwig Signed-off-by: Jianxiong Gao --- kernel/dma/swiotlb.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 781b9dca197c..6d6ff626c937 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -50,9 +50,6 @@ #define CREATE_TRACE_POINTS #include -#define OFFSET(val,align) ((unsigned long) \ - ( (val) & ( (align) - 1))) - #define SLABS_PER_PAGE (1 << (PAGE_SHIFT - IO_TLB_SHIFT)) /* @@ -176,6 +173,11 @@ void swiotlb_print_info(void) bytes >> 20); } +static inline unsigned long io_tlb_offset(unsigned long val) +{ + return val & (IO_TLB_SEGSIZE - 1); +} + /* * Early SWIOTLB allocation may be too early to allow an architecture to * perform the desired operations. This function allows the architecture to @@ -225,7 +227,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose) __func__, alloc_size, PAGE_SIZE); for (i = 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_list[i] = IO_TLB_SEGSIZE - io_tlb_offset(i); io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; @@ -359,7 +361,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs) goto cleanup4; for (i = 0; i < io_tlb_nslabs; i++) { - io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE); + io_tlb_list[i] = IO_TLB_SEGSIZE - io_tlb_offset(i); io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } io_tlb_index = 0; @@ -530,7 +532,9 @@ phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t orig_addr, for (i = index; i < (int) (index + nslots); i++) io_tlb_list[i] = 0; - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE - 1) && io_tlb_list[i]; i--) + for (i = index - 1; + io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && + io_tlb_list[i]; i--) io_tlb_list[i] = ++count; tlb_addr = io_tlb_start + (index << IO_TLB_SHIFT); @@ -616,7 +620,9 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, * Step 2: merge the returned slots with the preceding slots, * if available (non zero) */ - for (i = index - 1; (OFFSET(i, IO_TLB_SEGSIZE) != IO_TLB_SEGSIZE -1) && io_tlb_list[i]; i--) + for (i = index - 1; + io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && + io_tlb_list[i]; i--) io_tlb_list[i] = ++count; io_tlb_used -= nslots; From patchwork Mon Apr 5 21:02:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF29C433B4 for ; Mon, 5 Apr 2021 21:03:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7570A6113C for ; Mon, 5 Apr 2021 21:03:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241249AbhDEVDU (ORCPT ); Mon, 5 Apr 2021 17:03:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241227AbhDEVDN (ORCPT ); Mon, 5 Apr 2021 17:03:13 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CE45C061756 for ; Mon, 5 Apr 2021 14:03:04 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id jp20so368177pjb.2 for ; Mon, 05 Apr 2021 14:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=lvFPlljBb/WLm4WDC8t29VUZNx2UmX4AEMkM0T/oFwg=; b=u9Z4PAsHootLFVqdvJnzPekLU60WxhWrYmkkF9FnCZHi6VjxlP7aUiTTe4adGREi4a UJfr6ThwgOtnQCiReyZWtBB5Q7QdX/nZMXGDBQbE98ToK4lbtzb3rQjIKLTXiSB0TRYV Nc0DTAIP4UjdgrUYDmJITM0SFeQNNaEp83rlHBB2UA4gSR4DESFy2tf3UQHNbvhpEe/r ojfBqejBTyPlWFyqDP0QMgROqkqD+sTDDNdBP/mW5T+SULw8HmAtLmsK6RsegxUtylzm wO1v35kn1xAnkNI3wUjnq1FpsbmIp8TITrmlD81QsWd6pAemXgWZGkdKghh1dpzKBtG3 4RDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lvFPlljBb/WLm4WDC8t29VUZNx2UmX4AEMkM0T/oFwg=; b=GmJY0HlQuny29OOdLag/JEA3A8xAqc+kbzkzlmKrnpFi+ufaI8FcgMhYR96kjT9kxe /8yIx30x3W9fhxE1LEnTb+GgOIlLu21VYg10bYx98CBvYf9NF2dXpNgdJaUyXcPZXieC C0NBEj++rgfBTBL2o13BKT6+k/tR1xJ2ZAi6tbU/rOQEZAzX4RcnsX1IPm3BJcNQTO+P OFD/AeSidoCBPfSZIQSLPO0SnTN6DfYY+ggT2SS7jXpe5swUnVG19PngaWKz9P0Ufj4p m7awNKyhzu2zHO1rod3UHgAqsFEeBdOG0VSqIhmqek232WNpV/4Qj5oFcE1t8+zFCGjF yAgA== X-Gm-Message-State: AOAM532dcELYpbKaYujAksEBVS+bWgu1n/iXD7WdPkPAaNzcwcESeNat 0f5UfE9tIUOApzfvLCfC1gmyb1ivweeP3tOOJrU5yuUgRHENd7KmNJiq6nhfkYcNFwuEigwHxli WVwPUgrZ7E/mg/GCdBYZ4nUqkSfKW6CFYBIdkR4glbw5ztFTjs//qBKWnCAI= X-Google-Smtp-Source: ABdhPJyJU2kvhPuczYO+cGyTpBAqQY7EkL+Rxf8TnXUYJaVerjN/w0mOgqRPk7I37XA6gmtJfbd1WckBIw== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:902:dc84:b029:e9:3601:607b with SMTP id n4-20020a170902dc84b02900e93601607bmr1616146pld.38.1617656583983; Mon, 05 Apr 2021 14:03:03 -0700 (PDT) Date: Mon, 5 Apr 2021 21:02:26 +0000 In-Reply-To: <20210405210230.1707074-1-jxgao@google.com> Message-Id: <20210405210230.1707074-5-jxgao@google.com> Mime-Version: 1.0 References: <20210405210230.1707074-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH v5.10 4/8] swiotlb: clean up swiotlb_tbl_unmap_single From: Jianxiong Gao To: stable@vger.kernel.org Cc: Jianxiong Gao , Christoph Hellwig Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoph Hellwig 'commit ca10d0f8e530 ("swiotlb: clean up swiotlb_tbl_unmap_single")' Remove a layer of pointless indentation, replace a hard to follow ternary expression with a plain if/else. Signed-off-by: Christoph Hellwig Signed-off-by: Jianxiong Gao --- kernel/dma/swiotlb.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 1ba8e1095dfc..47d5dfeffd0a 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -610,28 +610,28 @@ void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, * with slots below and above the pool being returned. */ spin_lock_irqsave(&io_tlb_lock, flags); - { - count = ((index + nslots) < ALIGN(index + 1, IO_TLB_SEGSIZE) ? - io_tlb_list[index + nslots] : 0); - /* - * Step 1: return the slots to the free list, merging the - * slots with superceeding slots - */ - for (i = index + nslots - 1; i >= index; i--) { - io_tlb_list[i] = ++count; - io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; - } - /* - * Step 2: merge the returned slots with the preceding slots, - * if available (non zero) - */ - for (i = index - 1; - io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && - io_tlb_list[i]; i--) - io_tlb_list[i] = ++count; - - io_tlb_used -= nslots; + if (index + nslots < ALIGN(index + 1, IO_TLB_SEGSIZE)) + count = io_tlb_list[index + nslots]; + else + count = 0; + /* + * Step 1: return the slots to the free list, merging the slots with + * superceeding slots + */ + for (i = index + nslots - 1; i >= index; i--) { + io_tlb_list[i] = ++count; + io_tlb_orig_addr[i] = INVALID_PHYS_ADDR; } + + /* + * Step 2: merge the returned slots with the preceding slots, if + * available (non zero) + */ + for (i = index - 1; + io_tlb_offset(i) != IO_TLB_SEGSIZE - 1 && io_tlb_list[i]; + i--) + io_tlb_list[i] = ++count; + io_tlb_used -= nslots; spin_unlock_irqrestore(&io_tlb_lock, flags); } From patchwork Mon Apr 5 21:02:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFC91C433ED for ; Mon, 5 Apr 2021 21:03:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B93B661007 for ; Mon, 5 Apr 2021 21:03:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241259AbhDEVD0 (ORCPT ); Mon, 5 Apr 2021 17:03:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241237AbhDEVDR (ORCPT ); Mon, 5 Apr 2021 17:03:17 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C74C6C061788 for ; Mon, 5 Apr 2021 14:03:09 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id e6so1717796pls.16 for ; Mon, 05 Apr 2021 14:03:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=8EqNrvwkdxIVET2zGHel+i15pcUppE3BUHuAXOCRu9A=; b=ElbG+ls2SrN1CoymPx4ZWhtpqVC1gKGQDtHSJXI0uMAMwel4JmIcmmdgnZMSN2P1Wl jkimY4voGRce6I8UfP1FXs+GTRdXYV3urwt5kHwLofD5rmpsgPuLGxJ7OH1Ib+E+2KYu 5ImJleH9fB6Q4vj6SD3oId8AUoosAvUk2mUP9XxTI4kvRRpP38nDs+DI9TuZIKFv2Z9q jbKTpfCxBMcjLWJBP/VMWljCmavV/ZBlchrkMrk7L4RIbme1i0wUaaQfQRopF6NA2AP2 0jTe3IBJ8TMeNTQPrYJo3ixMzT91YdajvFpAWABM0dFSJ9G941wFiPOniSC7+qNx67VE LFIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8EqNrvwkdxIVET2zGHel+i15pcUppE3BUHuAXOCRu9A=; b=Pm6GgbsbEv+9tWdkT+Z8FoI4bMITLkdlf8TAk6L44k+/c3q4CH84KYtyzpLfdqxmCt WHDhZgkYRtwjOb0Fnsjw+z0CRbXGdEA4W8qZGxqerFAp5P/ycPWX1TFUFj8UxOlJ1SGu 8uFbzWp3MorAI8A4eHOkcb3v3/bpzT/TsqQ4whgz0IAliLbwbTd+/Z+vXoWug+FYB4H4 HX/2gSAmu7A27F6Qrrhf/aYzmkBhStgfCUUOZmeRw/KWqW9ZNRMZ/Kzc4POpFJXu1CCo ALhTxD51DXLLhop3UkygZmvXvTWjGAl4rGBw3IfEa4K0trGDnUURqHqki3JxTjGZbG/K +AHw== X-Gm-Message-State: AOAM530RzfC7l1eOvGoIoDsD/6ONevio9DNvYyAP0Aq/v+i2kMe41DkI af1y/0ZH0ay4lKIhEBfMPF5ags7GzSMxLOXk6ZjIinshhXgYa5D3nUjyxMKjZbrhcMJbcDKib6G WUWDyNiJcr548n3kLnzFr/kXftlzYLUpkceg56FMfygaboenvN3eVRq9NvIA= X-Google-Smtp-Source: ABdhPJzv6pUJAM1EvVFH9AyPIDLN6lypS/UIImyb9PlYOkeWqcLO+sJsppTr9aihegOi+LWwuRSDuHoClw== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:90a:24b:: with SMTP id t11mr174540pje.0.1617656588949; Mon, 05 Apr 2021 14:03:08 -0700 (PDT) Date: Mon, 5 Apr 2021 21:02:28 +0000 In-Reply-To: <20210405210230.1707074-1-jxgao@google.com> Message-Id: <20210405210230.1707074-7-jxgao@google.com> Mime-Version: 1.0 References: <20210405210230.1707074-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH v5.10 6/8] swiotlb: don't modify orig_addr in swiotlb_tbl_sync_single From: Jianxiong Gao To: stable@vger.kernel.org Cc: Jianxiong Gao , Christoph Hellwig Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoph Hellwig 'commit 16fc3cef33a0 ("swiotlb: don't modify orig_addr in swiotlb_tbl_sync_single")' swiotlb_tbl_map_single currently nevers sets a tlb_addr that is not aligned to the tlb bucket size. But we're going to add such a case soon, for which this adjustment would be bogus. Signed-off-by: Christoph Hellwig Signed-off-by: Jianxiong Gao --- kernel/dma/swiotlb.c | 1 - 1 file changed, 1 deletion(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index a3c0ccc53b8d..d1349971f099 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -639,7 +639,6 @@ void swiotlb_tbl_sync_single(struct device *hwdev, phys_addr_t tlb_addr, if (orig_addr == INVALID_PHYS_ADDR) return; - orig_addr += (unsigned long)tlb_addr & ((1 << IO_TLB_SHIFT) - 1); switch (target) { case SYNC_FOR_CPU: From patchwork Mon Apr 5 21:02:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.2 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A778C43470 for ; Mon, 5 Apr 2021 21:03:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5201B61007 for ; Mon, 5 Apr 2021 21:03:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241260AbhDEVD1 (ORCPT ); Mon, 5 Apr 2021 17:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237049AbhDEVDX (ORCPT ); Mon, 5 Apr 2021 17:03:23 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF01C06178C for ; Mon, 5 Apr 2021 14:03:16 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id e8so47570pfd.1 for ; Mon, 05 Apr 2021 14:03:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DwT0KnEuUIJq24rdQeE8mKCkjKjD8jpbcE4NrdQ1jDk=; b=Fr8qThzIql+f5dVI1DPyzBCYZ7bW8to0OlpnA1PtfpUJElz6tg0FmtJko4VvDpjshN jTVOPsJ1eqJSiYM3A5BjmhzetT+XommnohAHrgUaDDlx/skjdLtTpFxQMGyQQmk8XcBU wjKZ2cpR+ZcDuzMn0pk60CXBrijqdI3zI15EL6t+I/KIlXWeu7SArD7sOiQzPWp+IcdF MSxE/YMjq+xIpiXVZLzVeixM6Ze91xE+sFVfC8R0XdsfQ54okPE26EuXBX8xnoxdt4wZ tOLoBtZ9cIfACWsGQ3WRYqlFQatove9of2R2uickyQcqRcYseD/z37AUasQ1z8xYoMQg c8jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DwT0KnEuUIJq24rdQeE8mKCkjKjD8jpbcE4NrdQ1jDk=; b=Be8awOpL52aDOtj3TXCgV13NwqLkYlJV0BCb0HR1HUFnIq+cM7iOiCjHVqrU0wBmwD ekv9rWBM7wSMZJFVawoDwBZD3eH8FrdfDi9WVaL7GkGb9+noTI3nknykCmexIbN1SgxE UX3zXHhcNFoyWzdHncRRKfB02n1kV60xnF7zbhNEVwXWBE5pyVN/RsOXiO8QFduQ/UAy VdewI6ma6nxqWKRrCFIs0lMJK5GOxNIEDRrMW0JhLQaMa6h5x4/+Eg2sPPdKQEmdDM6L C5UiaGMVlcHaQfE0TU2NSsnCQRlImgsuUj/f1EVmMj0U++JM8q/WYmHhlMSjrZpeV5nD B6wQ== X-Gm-Message-State: AOAM530HVggLcRbxw91yJa4eaTOcCxy2ilDyBI0/VI9/IQWDhkPhK2L1 +E7CkltFgPl6YWDoc5ewiTp5nbf0wcpqhqDMg1p7qEnBv/JNFjU2oB81hhtRaEAhrL+ejQc5zO6 H5S6yKpGcIxV2HHKo8OOVhGontjEi2rwmAACP3hVU7aGdnHq8OjVHSlG3EjM= X-Google-Smtp-Source: ABdhPJwzGYBi3h+DeSc4okTkcRpTXY5f48FNdVL17pSatP67jZ3c3Nb72MJoDDhpwrHUxcCQSvhLqf42OA== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:902:dacd:b029:e5:cf71:3901 with SMTP id q13-20020a170902dacdb02900e5cf713901mr25018627plx.23.1617656596405; Mon, 05 Apr 2021 14:03:16 -0700 (PDT) Date: Mon, 5 Apr 2021 21:02:30 +0000 In-Reply-To: <20210405210230.1707074-1-jxgao@google.com> Message-Id: <20210405210230.1707074-9-jxgao@google.com> Mime-Version: 1.0 References: <20210405210230.1707074-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH v5.10 8/8] nvme-pci: set min_align_mask From: Jianxiong Gao To: stable@vger.kernel.org Cc: Jianxiong Gao , Christoph Hellwig , Konrad Rzeszutek Wilk Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoph Hellwig 'commit 3d2d861eb03e ("nvme-pci: set min_align_mask")' The PRP addressing scheme requires all PRP entries except for the first one to have a zero offset into the NVMe controller pages (which can be different from the Linux PAGE_SIZE). Use the min_align_mask device parameter to ensure that swiotlb does not change the address of the buffer modulo the device page size to ensure that the PRPs won't be malformed. Signed-off-by: Jianxiong Gao Signed-off-by: Christoph Hellwig Tested-by: Jianxiong Gao Signed-off-by: Konrad Rzeszutek Wilk --- --- drivers/nvme/host/pci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 3be352403839..dddccfe82abc 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2590,6 +2590,7 @@ static void nvme_reset_work(struct work_struct *work) * Don't limit the IOMMU merged segment size. */ dma_set_max_seg_size(dev->dev, 0xffffffff); + dma_set_min_align_mask(dev->dev, NVME_CTRL_PAGE_SIZE - 1); mutex_unlock(&dev->shutdown_lock);