From patchwork Thu Oct 7 18:06:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 1537882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=gh5CScF8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HQK681Lksz9t0p for ; Fri, 8 Oct 2021 05:07:10 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mYXnG-0004Lb-7r; Thu, 07 Oct 2021 18:06:58 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mYXnD-0004Kk-0S for kernel-team@lists.ubuntu.com; Thu, 07 Oct 2021 18:06:55 +0000 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id BAD0A3FFD9 for ; Thu, 7 Oct 2021 18:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1633630014; bh=7L6psQhjWjIl0SWbjfkwg1OZpiINxTAmlprEZlmk5ts=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=gh5CScF8K2p1LbnxU56nn68eKqtTTkLD5VVnma2fMNsnuxHODE9ZAT5/cYRbZtlAk UHKe11qL6LkFy2jZJRzxy37OYG/z4Y67A8lC5BaeSxv6eF27GNtW2fsqiXxbxlktiq 7i3WsUOehFTpDezCWaVRsC1ILe0HV8kjTdOlnSW+pPWT6Wnatd/ei/9Z+buFnmSlKO bB5efG0wfy6rIVWfT18FN9rVpFaJoXhtZLpElFMI/qCSq3sbgZcZIqNe/hoBQf+I7r mFJn/WXwp7k+sb1nD6bHrjtTMCegFZYDUU8vdtmHyN/keVnsh49LEz5YL0wZRxfZ9v +oAIG/+JFXHvQ== Received: by mail-qv1-f71.google.com with SMTP id m10-20020ad4448a000000b003833687f674so1643812qvt.2 for ; Thu, 07 Oct 2021 11:06:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7L6psQhjWjIl0SWbjfkwg1OZpiINxTAmlprEZlmk5ts=; b=0jL4FjdEHaSgmq489inUW9CYtHatvgMZODWEGwWxL7baLhY5Dmsuce1Y87LwJHDF9+ OkHMeT/ftljk9YeRXdrJRAf3SiU42BROpwfeD/A8Fy9quKlr2capDBhgbceD+KqDOj1I zAjjQvwSzu/PccrBifb/hdjs2gGGQ59/XXq0kzd1o0GU3vJdmYlBEcZQGtxf8itnI66h WzfAdIHPUbBAZ79BAWox4GB8i1xfTthBvnHfjf27568VknB3PJcxRiNWxNpazfXhttqq osJEYvoehMHUgfkEyY6kpiB+pKNkKIaLrkVqnaQOwPOhj0UUAfWK/gDQKU5KYBIpziWn tcqQ== X-Gm-Message-State: AOAM532CSjyrnIwLMEXS7YNXflTQC5Fw94aCVBhr5gRpvOkXhVaRWxbq JluDIClg5quyyYQhNoOkuB+SYeGoNX6PN9s6WgNtZUuqP2T6fkQE8FR+TgdLdd5mQ1C/znS6w/V 1qiL/+sjjALMOPCiicFBH2EagVsoyN+XXL+Nc66whXw== X-Received: by 2002:a37:2d04:: with SMTP id t4mr4367877qkh.463.1633630013863; Thu, 07 Oct 2021 11:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpRX2xPpFE5iF0ODBwAyH0CVd98m6QMyktYXXqAHVJ/JCEUFxaHsDCw+5o8ZntjvhBdQIFdg== X-Received: by 2002:a37:2d04:: with SMTP id t4mr4367854qkh.463.1633630013613; Thu, 07 Oct 2021 11:06:53 -0700 (PDT) Received: from kbuntu2.fuzzbuzz.org (dhcp-24-53-240-12.cable.user.start.ca. [24.53.240.12]) by smtp.gmail.com with ESMTPSA id o22sm72382qkk.132.2021.10.07.11.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 11:06:53 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [SRU][PATCH 03/13] swiotlb: factor out an io_tlb_offset helper Date: Thu, 7 Oct 2021 14:06:34 -0400 Message-Id: <20211007180644.9187-4-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211007180644.9187-1-khalid.elmously@canonical.com> References: <20211007180644.9187-1-khalid.elmously@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Christoph Hellwig BugLink: https://bugs.launchpad.net/bugs/1943902 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 Acked-by: Jianxiong Gao Tested-by: Jianxiong Gao Signed-off-by: Konrad Rzeszutek Wilk (cherry picked from commit c7fbeca757fe74135d8b6a4c8ddaef76f5775d68) Signed-off-by: Khalid Elmously --- 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 af41300592024..db265dc324b99 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; @@ -360,7 +362,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; @@ -534,7 +536,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); @@ -620,7 +624,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;