From patchwork Wed Oct 13 06:49:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 1540242 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=NUCUXx8L; 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 4HTjpW6b0sz9sR4 for ; Wed, 13 Oct 2021 17:50:27 +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 1maY5j-00065v-IA; Wed, 13 Oct 2021 06:50:19 +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 1maY5g-000648-RR for kernel-team@lists.ubuntu.com; Wed, 13 Oct 2021 06:50:16 +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 9F5383FFDE for ; Wed, 13 Oct 2021 06:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634107816; bh=FvPHV19oToPSJBNSTdghLB2cQgWs8wGb+Fn5gaA5nYc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=NUCUXx8LfRbrHGtGwB6amN68ehDQw8z7SEUXW1tZPC6Lb9c99ZkJKcIMVCzKi2gUy 62RWCHgMtYsK4S8ujK9SuWwSqRi4tscKS7i1yWOtsHlLjZhwgYQsg8wosCYxBYLKdd Uk3Jvym8Kp00rmeQn6B7VlzTflmPv00QZCkHyUd7dC1CS04okxUtvN98rZQze449ze XZvJ5sMVyxv/xW+a6scX7pH/fOHQ8LJ8WXM5lYhzMCG1aUosY+D77bivTYftBj2vD/ Mq5Sosh/siyrrH4AVGhfM/PXq1HgE8F3tQEdqi41h+HGRrlr5+GOLAXHpC8VR/yjeU nO0T/h/yZuOcg== Received: by mail-qv1-f71.google.com with SMTP id fq15-20020a056214258f00b003831673b6bfso1736148qvb.15 for ; Tue, 12 Oct 2021 23:50:16 -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=FvPHV19oToPSJBNSTdghLB2cQgWs8wGb+Fn5gaA5nYc=; b=eIJULrqvBFWrH5cpC2kbJEC8n83U3Xn1endRcfjDvH/G/VkkxX2BowOWqZn8QKt2Ix gyLAPgz6pjH1mw1pfLlnNoRWpV32/aWn1WLwKTcclU9JlSOjU9SNBMtQVouOgmTpW5iS aQ3L3ebb2kyq5IzURpLhRTeq7uX5/QmAIenKsB/zqZwmSyLTy53apclPJqr7u4dMnTvr UPT8DN8jvL/8oDEhXyZMOhEDCAe4FYOpdaX+MK7wIjDdSzEvF3fAQZv5l7R/ShuaH3zk 5E9edxDwJvy5qpmIE4aQfN0uvR18dZbp6LIUFTcfbD3QDjnNpy/ciepBv1iMsvCrV0nu IP4A== X-Gm-Message-State: AOAM533UKeM7vO5HpKmDVSkoW+OZrAKbWYxenled7xlv1B0RKsMEn/b8 WyKqq1ds/i9yKsf/WqbKPiIj1ipgxTowkvcKyp9PHuKzVTwqyEq9PLtAUozbcPnd7zr8oI9Zkyf s7wU0u8kwCB4yjoOQNL5+LHNH2mGJmSPcGc6wLqAjUA== X-Received: by 2002:a0c:b4c9:: with SMTP id h9mr34127733qvf.6.1634107815728; Tue, 12 Oct 2021 23:50:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwTUlCeJWFI6sxpRJQd1PrtRA1Gf8HiWThcYemdjW5R++6jVIS59zyc9Gf1h7Cnrel77YY2A== X-Received: by 2002:a0c:b4c9:: with SMTP id h9mr34127723qvf.6.1634107815449; Tue, 12 Oct 2021 23:50:15 -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 t19sm5727298qtn.26.2021.10.12.23.50.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 23:50:15 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [PATCH 04/13] swiotlb: factor out an io_tlb_offset helper Date: Wed, 13 Oct 2021 02:49:58 -0400 Message-Id: <20211013065007.1302-5-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211013065007.1302-1-khalid.elmously@canonical.com> References: <20211013065007.1302-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 fc2af340053b1..1f29e5eb5356d 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; @@ -531,7 +533,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); @@ -617,7 +621,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;