From patchwork Mon Mar 30 02:32:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 11464499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78B041392 for ; Mon, 30 Mar 2020 02:34:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4582020780 for ; Mon, 30 Mar 2020 02:34:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="w1Utm7e6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4582020780 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=joelfernandes.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B3E6A6B0082; Sun, 29 Mar 2020 22:33:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AC6966B0083; Sun, 29 Mar 2020 22:33:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8538A6B0085; Sun, 29 Mar 2020 22:33:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 6E7346B0082 for ; Sun, 29 Mar 2020 22:33:50 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7996A40D6 for ; Mon, 30 Mar 2020 02:33:50 +0000 (UTC) X-FDA: 76650458220.19.art11_5bb7b99f68e30 X-Spam-Summary: 2,0,0,d93b20965dc9f6ab,d41d8cd98f00b204,joel@joelfernandes.org,,RULES_HIT:41:355:379:541:800:960:965:966:973:988:989:1260:1311:1314:1345:1359:1437:1515:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3871:3874:4321:4385:4390:4395:5007:6119:6261:6653:6742:7875:10004:10394:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12895:13069:13311:13357:13894:14384:14394:14721:21080:21444:21451:21627:21740:21789:30054,0,RBL:209.85.222.196:@joelfernandes.org:.lbl8.mailshell.net-62.2.0.100 66.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: art11_5bb7b99f68e30 X-Filterd-Recvd-Size: 4882 Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 30 Mar 2020 02:33:50 +0000 (UTC) Received: by mail-qk1-f196.google.com with SMTP id i6so17556407qke.1 for ; Sun, 29 Mar 2020 19:33:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bIwgeh9rHwo41HBlXUss+pfAH9DbFE6iCebsly3ZN4c=; b=w1Utm7e6d4/535TdQtPiMXksX4j1qcmln0qSp2Ce5ITm627q5dnSU8lnhyBq3uY9oE 0PhDmMsluIYgdTjcV+PSd7sVQ/WGe+IhJGHMYogCDZYqSvqJL1tsZLjyg/tB9D7Y4aYN zqy3An60oNrntByo8BqUBrC2oSWocnndGjLG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bIwgeh9rHwo41HBlXUss+pfAH9DbFE6iCebsly3ZN4c=; b=j1ClIH/i3gqDC0HWl7ulOBlBX62xBRRyBl2dJN+uOgqmrZnDRSDWVz57T7V75IQQAM R+miJ0O0yQ6CgKjmQeRjIlAim3iXI32Txe+7B3BCCnArt/gFEooTQgKu5xrW9eNTKfX2 89TyRAX0CECftVPwrhoUqXlV7/WhMUQr1Asm1mDqsMvYmd5FpfgO5QySq+Vd5qNzWoud HN5HTdzWXCWTPOeGV94XssthOcFmiZyT3a+SmuTmKxcg7Lubl/3LItdPCxd+7OQr7b5h 7cNwlcO82EXZu0Wh2WBS1lSuCGkHHOtKMFOELx2rk4kz25BDxriDbn+Ea6x+ne23MhY/ Aekg== X-Gm-Message-State: ANhLgQ2+ammUql40FbX4eb7NBsW49n6E9LzpEh/QHGgJ+bVElk9xl5XB 8vvpWaLN7PiG7NQ+e0ymnNVzVw== X-Google-Smtp-Source: ADFU+vurXBFAw9FRqEBRvtnmRBiIAJYMQMQAx1nAenRxy7DRsubkevgiGpgtf0ZMZlIvcVQv3d7mpA== X-Received: by 2002:a37:a68e:: with SMTP id p136mr9993192qke.7.1585535629357; Sun, 29 Mar 2020 19:33:49 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id q15sm10030625qtj.83.2020.03.29.19.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Mar 2020 19:33:48 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Andrew Morton , Ingo Molnar , Josh Triplett , Lai Jiangshan , linux-mm@kvack.org, Mathieu Desnoyers , "Paul E. McKenney" , "Rafael J. Wysocki" , rcu@vger.kernel.org, Steven Rostedt , "Uladzislau Rezki (Sony)" Subject: [PATCH 18/18] rcu/tree: Make kvfree_rcu() tolerate any alignment Date: Sun, 29 Mar 2020 22:32:48 -0400 Message-Id: <20200330023248.164994-19-joel@joelfernandes.org> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog In-Reply-To: <20200330023248.164994-1-joel@joelfernandes.org> References: <20200330023248.164994-1-joel@joelfernandes.org> MIME-Version: 1.0 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: Handle cases where the the object being kvfree_rcu()'d is not aligned by 2-byte boundaries. Signed-off-by: Joel Fernandes (Google) --- kernel/rcu/tree.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index 311d216c7faa7..d6536374d12a9 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -2827,6 +2827,9 @@ struct kvfree_rcu_bulk_data { #define KVFREE_BULK_MAX_ENTR \ ((PAGE_SIZE - sizeof(struct kvfree_rcu_bulk_data)) / sizeof(void *)) +/* Encoding the offset of a fake rcu_head to indicate the head is a wrapper. */ +#define RCU_HEADLESS_KFREE BIT(31) + /** * struct kfree_rcu_cpu_work - single batch of kfree_rcu() requests * @rcu_work: Let queue_rcu_work() invoke workqueue handler after grace period @@ -2970,9 +2973,9 @@ static void kfree_rcu_work(struct work_struct *work) next = head->next; /* We tag the headless object, if so adjust offset. */ - headless = (((unsigned long) head - offset) & BIT(0)); + headless = !!(offset & RCU_HEADLESS_KFREE); if (headless) - offset -= 1; + offset &= ~(RCU_HEADLESS_KFREE); ptr = (void *) head - offset; debug_rcu_head_unqueue((struct rcu_head *)ptr); @@ -3221,7 +3224,7 @@ void kvfree_call_rcu(struct rcu_head *head, rcu_callback_t func) * to the original allocated memory, that has to be freed as * well as dynamically attached wrapper/head. */ - func = (rcu_callback_t) (sizeof(unsigned long *) + 1); + func = (rcu_callback_t)(sizeof(unsigned long *) | RCU_HEADLESS_KFREE); } head->func = func;