From patchwork Thu Feb 2 01:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 13125203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 001ECC636D3 for ; Thu, 2 Feb 2023 01:42:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EC416B007D; Wed, 1 Feb 2023 20:42:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BC56B007E; Wed, 1 Feb 2023 20:42:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73CA36B0080; Wed, 1 Feb 2023 20:42:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6099F6B007D for ; Wed, 1 Feb 2023 20:42:25 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F36D140DC1 for ; Thu, 2 Feb 2023 01:42:25 +0000 (UTC) X-FDA: 80420651850.07.F421770 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) by imf16.hostedemail.com (Postfix) with ESMTP id 60646180005 for ; Thu, 2 Feb 2023 01:42:23 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XgJCNvo3; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675302143; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HRKKHzUPeYRgy9sp4sc6HU9jmgQ/kndp4UTR0lBuLfE=; b=kbsvRuQshkNh5vW7k6Iur2aFj7wIpieQspSK4lpea4z1Fca/i6/jau4ZvOf8AnhH96PXTB Mv23+mHjy12JfLdz/YfXwasxL/Eyd64jzkuR/6GUjLo0y2zfUd5BuPcFTvIB86RYyJ6Wlp KKB4sZ7adpl1ch2SQeTOr6vprGMwDeQ= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XgJCNvo3; spf=pass (imf16.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.216.49 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675302143; a=rsa-sha256; cv=none; b=BVUHmw4wvqw61fB1inwOq+hUY9LfMA67bZYs9SRbBXqQA/LP5sNwENO91Co5rBEkqVndcs dqVFQYQvNm2FSg6ObJLCNI+8HpO4tLIBwhcsSBOgDiEzjxZi1D4sEggbHJEXPOtE+7A7bC 1dZAw6to8AoO0jL2tIJ2ik+enNjSj6Q= Received: by mail-pj1-f49.google.com with SMTP id mi9so502731pjb.4 for ; Wed, 01 Feb 2023 17:42:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HRKKHzUPeYRgy9sp4sc6HU9jmgQ/kndp4UTR0lBuLfE=; b=XgJCNvo3Mxgtg5Cm1ISnzALszmieUGA5g+mJmIl1lai7/r9rTtYkS3lVzxT8o3lN9P M07KKCtnz0xTxGyblruhALIg8QtCdiv0QIEPRfGk63fKr+7soH35NVOt9nlCiG6uZMI1 6C8k8MP6uMuCdf3W9QcjepEoOVtGmdI8Wp/s/Q9Z2mWDgX2AAC4YUXmgK4/NU1E5OFtY bm1PQVqxf9D4x3Wiski2pMGKHx1GH+/fEne7NjldfB6ly5ft+PiCb2uiJJ1G/VxOcJee wrj6uM4nSHqYrDuB9s+QK7xx9U+P75pCWOuCwgfEHRqrLxuxOo0FpP9kShHIcslp/3gK +WAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HRKKHzUPeYRgy9sp4sc6HU9jmgQ/kndp4UTR0lBuLfE=; b=8HgoDtbSbvMgFjXr0VaK2wHbN14h4KXpeN6nJgb+9Xapq9UrvlHn679oFVfGzeHf8y uBMLDnRa1G4uwGzuHIy2wuPWwGpBmoe5BF5eoCr7CsPcBCgDRtC0X9odZm7rtEC0tl8R p3n85RPEPUmMwYWd8ts5RMPYgoBYpwz6QxQH03/jkqanCrQpUwkCRex+6KYGwHJ1uuGl X2L5fXrtIAhqL9vo9VCxNDq5QgiTyex5OWVuSaqEwhucYgANYe25MBnViKLZJwW4HoY7 zy14zB19Il3OvA/573J4JhSRgDZbelES0E1rax3l1fyhVa12h8cNYG/z9qQ4l7SDZnLW zJDQ== X-Gm-Message-State: AO0yUKUx25ctkFCwbCcOWKp8E/569/FWLrsf6PW+GLGPUB9RxTZvLg5P xcFY0M3OkY1vyyJR+1NKM0E= X-Google-Smtp-Source: AK7set9GF2+wbpIKssdijZ0MvTlGQkES0Y8qB6dhHwsPA23hO7kBC462w0w9sb2JVm95BPkSBvmTuQ== X-Received: by 2002:a17:90a:1997:b0:230:3af9:177 with SMTP id 23-20020a17090a199700b002303af90177mr693628pji.8.1675302142358; Wed, 01 Feb 2023 17:42:22 -0800 (PST) Received: from vultr.guest ([2001:19f0:7001:3f48:5400:4ff:fe4a:8c8b]) by smtp.gmail.com with ESMTPSA id t191-20020a6381c8000000b004e8f7f23c4bsm6594205pgd.76.2023.02.01.17.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Feb 2023 17:42:22 -0800 (PST) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, tj@kernel.org, dennis@kernel.org, cl@linux.com, akpm@linux-foundation.org, penberg@kernel.org, rientjes@google.com, iamjoonsoo.kim@lge.com, roman.gushchin@linux.dev, 42.hyeyoo@gmail.com, vbabka@suse.cz, urezki@gmail.com Cc: linux-mm@kvack.org, bpf@vger.kernel.org, Yafang Shao Subject: [PATCH bpf-next 2/7] mm: percpu: introduce percpu_size() Date: Thu, 2 Feb 2023 01:41:53 +0000 Message-Id: <20230202014158.19616-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230202014158.19616-1-laoar.shao@gmail.com> References: <20230202014158.19616-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 60646180005 X-Stat-Signature: 9tte9pme3bq8mtfm69nryx9d7m5r7ain X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1675302143-641582 X-HE-Meta: U2FsdGVkX18B3nchwGrf0VRPZzEB6YJty8LwF7TJVMZOUFyI/8zCdz77Z3yKeIwJOA2EJGiqMNuqr03nlR3RggGPql3w8nFxyH19McqUI/3D014DgJQ8uSOoKIfYX7jd4PzSu3zpTd7G8+kqjZRkUEX/yhLyqx+SuszrihDylmAn2wCJvzo+XTixmfmuVT1tPr7MRQRULx7IsGMBuAwrGNJe0NmQ+qDSAVa9hvFEC0DS4Fxt1v1hRO2I2t1bOiqSCNwUCy0R/yk4DMi7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f/mC1Eyu+knSshTMZV9fnUZ3MeCcvKe0sa8E7IN4usRqfT4pg1Fi7PizuM1vNrY5TW8vGe98kwlWbOO5Mx/Yw6d0/mA4+b6LKHUqmcH1pzyqST1WZSEqQtv2ijjglL5S1MdWRSSTnF7YbTU+B805Czucy+j6FhtLG1Dhim0sNVsELlxzXQ87Ep+pXQHImF0K3LHsj0K6+M7dqRX8s0E8hdwHA3qRKtd/KPuXxi1kdq9ZY8bVEN2qRJ5ku/HopTxII3wnS4W2b9gtpcTowXbq1kMihCYMoJ/Lj0sgZ5uKEvFGTUP0PJuboRSKMMsaA2lfqTBepWACKCWVdFj8fd7BFsK7OwUJr0yZZhj78C9a4ovc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Introduce a new helper percpu_size() to report full size of underlying allocation of a percpu address. Signed-off-by: Yafang Shao Cc: Dennis Zhou Cc: Tejun Heo Cc: Christoph Lameter --- include/linux/percpu.h | 1 + mm/percpu.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/linux/percpu.h b/include/linux/percpu.h index 1338ea2..7be4234 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -137,5 +137,6 @@ extern int __init pcpu_page_first_chunk(size_t reserved_size, __alignof__(type)) extern unsigned long pcpu_nr_pages(void); +extern size_t percpu_size(void __percpu *ptr); #endif /* __LINUX_PERCPU_H */ diff --git a/mm/percpu.c b/mm/percpu.c index acd78da..5580688 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2302,6 +2302,41 @@ void free_percpu(void __percpu *ptr) } EXPORT_SYMBOL_GPL(free_percpu); +/** + * percpu_size - report full size of underlying allocation of percpu addr + * @ptr: pointer to percpu area + * + * CONTEXT: + * Can be called from atomic context. + */ +size_t percpu_size(void __percpu *ptr) +{ + int bit_off, bits, end, off, size; + struct pcpu_chunk *chunk; + unsigned long flags; + void *addr; + + if (!ptr) + return 0; + + addr = __pcpu_ptr_to_addr(ptr); + + spin_lock_irqsave(&pcpu_lock, flags); + chunk = pcpu_chunk_addr_search(addr); + off = addr - chunk->base_addr; + bit_off = off / PCPU_MIN_ALLOC_SIZE; + + /* find end index */ + end = find_next_bit(chunk->bound_map, pcpu_chunk_map_bits(chunk), + bit_off + 1); + spin_unlock_irqrestore(&pcpu_lock, flags); + + bits = end - bit_off; + size = bits * PCPU_MIN_ALLOC_SIZE; + + return pcpu_obj_full_size(size); +} + bool __is_kernel_percpu_address(unsigned long addr, unsigned long *can_addr) { #ifdef CONFIG_SMP