From patchwork Mon Apr 5 20:51:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415599 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 E0A91C433ED for ; Mon, 5 Apr 2021 20:51:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B465D613CA for ; Mon, 5 Apr 2021 20:51:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235873AbhDEUwB (ORCPT ); Mon, 5 Apr 2021 16:52:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232860AbhDEUwB (ORCPT ); Mon, 5 Apr 2021 16:52:01 -0400 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6391EC061756 for ; Mon, 5 Apr 2021 13:51:52 -0700 (PDT) Received: by mail-pg1-x54a.google.com with SMTP id n23so3619713pgl.2 for ; Mon, 05 Apr 2021 13:51:52 -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=kXSoBS4HEON9UnWAMRtgPLba1XO2mEENMySZevqoKOw=; b=n0VBDfxrbbeF62K0CXNvQt26TveE0LJlKyGqHLyzi0uuvEGOCLQ9S77lGgs56j/0YX fDbfWRCV1UZtkmb/R4iDP3wCKh78Q2nXLcySHsZKvTC8gGYTio3ltqpuxDn1rbPSUWaQ CfDQtqxkPErHrr4WLaBBH5lyOE6bed94j5CVch56IGI8jov2Xn3Jm5s24wmxSKJdDwso fkleHfwDqv+dzut9SyV8+oSZxJhRakUEMfMbhMw2g5wNTg5B1vD4TBZyrTAF1bzYoiOd Dnby29pxCOGEl1v/7R7MJkvcaAcj9HFFF7DRi4NesrveElBEm953qq3riGaRVl7FWEnU gnYQ== 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=kXSoBS4HEON9UnWAMRtgPLba1XO2mEENMySZevqoKOw=; b=ehZ6hJFm6d6xGNluoqgywm3ZjJv6nE0nI5uDSv2lI6FaGCeK737HqChOx/BmEkYHRz w+rOzoxFf7i6u5C8sX2CQaDl9QJK0Ya/ivJRmBGWUqJ3krQ/kBf1bGWrSVSWcIq3tBRU nsFSh9xcTMpLbA147tbm044v4mHXoxPV6cOKdsRSw+BCcb7L2899HcrXHcbdCpiyNeZz jGjlaBTELBodqoUpC7FquTdpkbrs0NzDGqfh2YSXbIMOH4Bh5T7G+dztC6Ma0hZIJmSe xs4yP4a16dG79TI349duM0zOLBWf7OveW/2gcLYiZz3hLQPj7Z93dswBwQB1RrhyPFuT vYmA== X-Gm-Message-State: AOAM5304jVlOMEfemhjyAwMgwXq18IkzxKpmuJK6WPFI2FU0ePzLs/r3 b80iH0F6N8OkOZZZMU1UegzHsSRohGEQZ1LbBSdf4KWuZqQA9jIV/yQg4AdjkcbkcS4Irjfi5vB 1+xT75rrn6IuIP9rQFAZNsr11OxIyC2+gTjDSkaCnu0J4WUrvs2yQymfhIqg= X-Google-Smtp-Source: ABdhPJxkUH3RPiVJkT2Lhh2gz5QKJC8MLeeHhofmZ+rGEv6AAcnZXJoABV/49SSf7DhwFh/9bW3VW25XqQ== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:902:b68c:b029:e6:bb9f:7577 with SMTP id c12-20020a170902b68cb02900e6bb9f7577mr25301466pls.0.1617655911787; Mon, 05 Apr 2021 13:51:51 -0700 (PDT) Date: Mon, 5 Apr 2021 20:51:03 +0000 In-Reply-To: <20210405205109.1700468-1-jxgao@google.com> Message-Id: <20210405205109.1700468-3-jxgao@google.com> Mime-Version: 1.0 References: <20210405205109.1700468-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 5.4 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 673a2cdb2656..9fa71a91c235 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -49,9 +49,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)) /* @@ -177,6 +174,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 @@ -226,7 +228,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; @@ -357,7 +359,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, 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 20:51:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415598 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 30976C433ED for ; Mon, 5 Apr 2021 20:52:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB6CC613C9 for ; Mon, 5 Apr 2021 20:52:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237205AbhDEUwH (ORCPT ); Mon, 5 Apr 2021 16:52:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237144AbhDEUwH (ORCPT ); Mon, 5 Apr 2021 16:52:07 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 038C7C061756 for ; Mon, 5 Apr 2021 13:51:59 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id o1so9691333pgl.0 for ; Mon, 05 Apr 2021 13:51:58 -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=RGqcKbdPQxzBm5lgM+hyc0G6eeSvIiffmXl+rvemOPU=; b=BClaqHAfXcEj3CuT5fY8bzE8e04hJ7Vg8fQkd+h1rVwNx3NZsykj44BbtJxd+hWOMz ea59Use9Eb2c5KYrz8yyLD+5qnNsO/A0mRBoaskL33NOWjS7y4UHtmLbDKKdc3tYTJkT YqrZZ34mNFsMXjIHY91YxGTusWLLnLlJ2HeU5uppX6KRr7skbArD2nivI9ADSiFiD4MV UdWj0Ep9hbX1m/4//6Ze41Qj9wy7Y434hMHDrinq8QgbtFaKe/53X5ITBHl28P4FeLu4 znUvsQDcno7uZv+SQ/YCumiApONqAKHjAs6OegpOh9MnRZoi4CvTuVvT0jXu8BIxMoxi UKXA== 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=RGqcKbdPQxzBm5lgM+hyc0G6eeSvIiffmXl+rvemOPU=; b=fK3ezsrnKAiqBNTMg1H7dDU56jncsuReqg8tUhexX86+QuTGkLPkldFKRbAhugiXRB L9zy6gbt4ml1rV9x/pi+LiHVmn/ebaMfqccejCgqPPyr2MCI7Q6l9Z4Gg34dN+ovy1Ey k0ADV2x0OHYob+MCATPZbud41IL/o6+fQRCtwBHadiGaZwYNqMR68zHxX/yR8+VgJxPD 2YYNLcZqG9b61aD3SBx2rOuSH2FfEN8QN5zrBWYNr5esxKvLa2gHvJGr5b8QBofPBOpq aYM2P/0zdbZlH+8vOzDRON2iUdZr+Id8kG0DE5Cos3PuPkLO0N3fxEjkNwpt0VbSDMA+ xauA== X-Gm-Message-State: AOAM533qokmklIT19sc9NmdLnbPuQPxW2PwXHWMP+HcWbfDw2bZgK2ym mAaTj8BqFF0nCbIrJJgGTYaFM2TTZ8Ev7tyDdGEIENKj5ltstRxrP97E1BL74HD5I2a4igyoFTp 760KeSjUrYvpKF08Q5EYzgAdvF/XKX/VY4jAZPOveOrVbLyoatqZ5opEttGc= X-Google-Smtp-Source: ABdhPJyqIjnYaHUHXh3r+FKZXISIFJSHm9eBdx5yqzvZF+YtFGU1mV2FcOQp0VL887GA1edtv2ZA0nQaCQ== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:902:8693:b029:e8:fdd4:361c with SMTP id g19-20020a1709028693b02900e8fdd4361cmr7760737plo.32.1617655918462; Mon, 05 Apr 2021 13:51:58 -0700 (PDT) Date: Mon, 5 Apr 2021 20:51:05 +0000 In-Reply-To: <20210405205109.1700468-1-jxgao@google.com> Message-Id: <20210405205109.1700468-5-jxgao@google.com> Mime-Version: 1.0 References: <20210405205109.1700468-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 5.4 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 200afa87d135..5484469fa5f3 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 20:51:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415597 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 B8804C433B4 for ; Mon, 5 Apr 2021 20:52:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6CD1C613CA for ; Mon, 5 Apr 2021 20:52:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237209AbhDEUwN (ORCPT ); Mon, 5 Apr 2021 16:52:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237144AbhDEUwM (ORCPT ); Mon, 5 Apr 2021 16:52:12 -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 699D3C061756 for ; Mon, 5 Apr 2021 13:52:04 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id u5so6525276plg.2 for ; Mon, 05 Apr 2021 13:52: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=UTdKj8ocmS3qFB4iDfyzZRZ0xX14Ta3gzafAciDjQIQ=; b=A7CWfwEsG/RiJSmID/lPUPcyzvSpCxu11vZwOH8K+XGB+kyMov3hUUbQ2lKLJZN6Gc fEW0W6/AIGWK/kjMAEarPaGFNivoTGzExc1kzZZYkJQneptV+3l0rAYt45ElTMVDIiv7 GWdVrT8BMeRltutJ7iPITkGmq5TJjRmpoi3Wtp6zMQWqnXYH7ASNqL/SPg3hmJuhHIxF uf21Y2/rFgASKDeECUcDNlOlHbCgD2D1x+2GBxSNWUcF/G+x8Mj/dbjvbOlzRwUAHVFk NFQfKz3r+QEsApzAeNlAaagakOJoM5OgMXqJ08JwmAWWn+gN5iRyDX8VVPGNL06QziMn nAXg== 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=UTdKj8ocmS3qFB4iDfyzZRZ0xX14Ta3gzafAciDjQIQ=; b=qTZwFJdRlnFAK9bNc3NrdUWeMldZVgLacOmDZZOvcri7UUfStWdZSzlGkgVfZyKuN4 gf6Tyn2fz4+0h8inUGHmrBtfeJux95HnvXEAM7ZS32oOA/KCtdW+i48IX/4w+yOuMCSx jlJFtZ+opelM9Al2Q5TebCrdAj9AcB4AGearCkfLad9FvyvcYIvdvKJYOIB4dk9QqkbO 8nFUJft6vfI20+llm/fKU7j3FdtK1tu6NOyn3iymc9a5lKhfD+kMpHL5VVLB2AQSmHHg bpVlgUn33wLsewX/pNVMz+dszcaeQoP6cnRP+ukxJPve/tnrT/d5g+62YuZppegElKYw 8Xtg== X-Gm-Message-State: AOAM533N30A8zpnzB+iAp6XR0a40+qwgUBC0kJ3e7AH3rr3nyjX+4dKb yvQ6AkJ/FBNL+e2F1cfWOjTml3n1ap/SiYMH7cH1u5+x3iYO+fDwWeDb0FgyQJYj/mQVeOcQ018 YPwNvmBMp9vU85P5o1E3kJgDIlUmsRe5UENKy80oM0MhyQh3dRpF+EKBKFdY= X-Google-Smtp-Source: ABdhPJykqyjw7Ex/CXK/LY2xy7kXunYqCQLUWXCQ8QBpsUgIR1VAnLGofgM2qNB3je6Wo6C8KxRfKsnTkw== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a17:90a:df01:: with SMTP id gp1mr170094pjb.1.1617655923536; Mon, 05 Apr 2021 13:52:03 -0700 (PDT) Date: Mon, 5 Apr 2021 20:51:07 +0000 In-Reply-To: <20210405205109.1700468-1-jxgao@google.com> Message-Id: <20210405205109.1700468-7-jxgao@google.com> Mime-Version: 1.0 References: <20210405205109.1700468-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 5.4 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 dbd6cda6ace6..faf51614f02e 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 20:51:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianxiong Gao X-Patchwork-Id: 415596 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 72574C433ED for ; Mon, 5 Apr 2021 20:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DAF3613CA for ; Mon, 5 Apr 2021 20:52:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237225AbhDEUwU (ORCPT ); Mon, 5 Apr 2021 16:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237144AbhDEUwS (ORCPT ); Mon, 5 Apr 2021 16:52:18 -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 93B37C061756 for ; Mon, 5 Apr 2021 13:52:10 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id oj6so312526pjb.5 for ; Mon, 05 Apr 2021 13:52:10 -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=rePpgg0NtSFQvI03Pc8QaLoe8pSD5aFacV3/oLpjZHQ=; b=ZRTiEwiG+4b6sPnwdcIUTl2SBysqnBca1TYnqghxn86o7MzmKdJbBc2v/ZeQJSjl8g /z8dMokqdY15iLdZ3jm3DYC105gTvBTDm/Xgti4OSaZ7KnEID6lwgXZCTOSD8XQxGFt7 sNwuUfDnjjG2XlAgrojFlrlmhAMlriZ8Bmn/bezumvHay0Kc3uWk8OxVK/gzmDktANIA azsVxaS7VisV2NaWXvG0yLmn7aaGhNmZUpx3ClRTtON0/z0hKZuTnLe7z4Rbhpysc/iN Jx8VbxFFhsEwHcD0YXZTE9H/Ql/3qNcRzGm5WWmUX7HHZqOpf1hCnAWa9ukdzp4zgBzZ KAxw== 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=rePpgg0NtSFQvI03Pc8QaLoe8pSD5aFacV3/oLpjZHQ=; b=cFMCYeIIZHRUPno4ZjaoXFXmRmqAWMMoWMS7hj0P0gt9hzhrzshYEnE2ULzoXo/fr0 sh04fRssp/mVj5YdHbUnwluxL4lGwZq0Ebbs6BvOdR8gle7HKPzoPqn6ElSb072YLTLR 6uHsrZB/bRzJgA6QEfnEg0ul6mUXo1iD3c/yC0ypy8WlsSKbivBvbrr2zxEHGI8tUmOJ ViUYATIgNmlm9BABj7qti9Wfx6WJQvZhx9YY2cqxrWzNIeiKFDwDv+GMMyM8ZFHMD5yJ M2vK5dNjQl5S52aOtqQ2N+9Qce2PPv5Ly8SZobLs0iEx/QhIzYtnwHqx9NLP6TS/jfSL g7cg== X-Gm-Message-State: AOAM530CiZd+N0n0tzGxucdj90AjUrhkChSkCBkFXeBuqiTkP1IWo2SO 92vUg8eee0T8moIVpcwdK+Y50O7H0vsP7E8vW8u/HbD8+wZDz15rjRBXKHQuzZ5BMHcXfrf3o2x nQXBiGndOz8IoVxQKT5NBJHArrB8+UKxMW2iR4G9Eh8UE+j7Rct4ND0Y9LZg= X-Google-Smtp-Source: ABdhPJxX4VdSH0GHmJVZttmoP354Ny8oZT4sk/TmDzG57ZdNjsxS65rByo2Nes1iZG7VPmKh7/LO+l4c9Q== X-Received: from jxgao-snp.c.googlers.com ([fda3:e722:ac3:10:7f:e700:c0a8:1373]) (user=jxgao job=sendgmr) by 2002:a63:5562:: with SMTP id f34mr18820254pgm.391.1617655929958; Mon, 05 Apr 2021 13:52:09 -0700 (PDT) Date: Mon, 5 Apr 2021 20:51:09 +0000 In-Reply-To: <20210405205109.1700468-1-jxgao@google.com> Message-Id: <20210405205109.1700468-9-jxgao@google.com> Mime-Version: 1.0 References: <20210405205109.1700468-1-jxgao@google.com> X-Mailer: git-send-email 2.31.0.208.g409f899ff0-goog Subject: [PATCH 5.4 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 869f462e6b6e..087ae2b2a853 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -2576,6 +2576,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, dev->ctrl.page_size - 1); mutex_unlock(&dev->shutdown_lock);