From patchwork Wed Nov 27 14:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Wool X-Patchwork-Id: 11264193 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 9271F6C1 for ; Wed, 27 Nov 2019 14:23:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 549572064B for ; Wed, 27 Nov 2019 14:23:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NVsRjIUc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 549572064B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 75D4E6B04A4; Wed, 27 Nov 2019 09:23:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 70DB06B04A5; Wed, 27 Nov 2019 09:23:49 -0500 (EST) 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 64C446B04A6; Wed, 27 Nov 2019 09:23:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id 4EB576B04A4 for ; Wed, 27 Nov 2019 09:23:49 -0500 (EST) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id C9C712497 for ; Wed, 27 Nov 2019 14:23:48 +0000 (UTC) X-FDA: 76202276136.17.toes68_5b6dbea8e3e5a X-Spam-Summary: 2,0,0,cff3549f95ae7d46,d41d8cd98f00b204,vitalywool@gmail.com,::linux-kernel@vger.kernel.org:akpm@linux-foundation.org,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3352:3867:3874:4250:4321:4385:5007:6117:6261:6653:7558:7875:7903:9036:9413:10004:10400:11026:11658:11914:12297:12517:12519:12555:12760:12895:12986:13069:13311:13357:13439:14181:14394:14659:14687:14721:21080:21094:21323:21444:21451:21627:21666:30054,0,RBL:209.85.167.67:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,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:2,LUA_SUMMARY:none X-HE-Tag: toes68_5b6dbea8e3e5a X-Filterd-Recvd-Size: 4428 Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Nov 2019 14:23:48 +0000 (UTC) Received: by mail-lf1-f67.google.com with SMTP id 203so17288375lfa.12 for ; Wed, 27 Nov 2019 06:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NQAc09iOSs+OUg5bzPj2H1rBE2GvXaGtHzNxY2vVFm8=; b=NVsRjIUcwILPd1tnDv3S17qPH2Rc8pdEr06OlwognC5L1wYvuuWE2VmFAVum6Qb1sC lmVgIpOLWlVMCndd202EatqCqX9bWwKuQpuknmnYAvNBZuRM0nfXZWN+zzgPxEDxXtNP jo3HcmJ7bYOf3vgkcdZcmnDKCfYRUit71JHPUh0YjkuskgVPvkpJtC7gGesDIl5k/ASd TnVlq3uYhRek3JP6dVNkz96AweylBNW4uXW04xnsmUiSETC69B8fHHkaoIdGKO35hm8Y 2kalCjn+HqYa1IEXmMSEhDzdLjntmK6J3oLzeaoyaS1e+VSazkpj5LuLvCDr9RKRbaqp qWhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NQAc09iOSs+OUg5bzPj2H1rBE2GvXaGtHzNxY2vVFm8=; b=QkeHHJILpbG0okA2AIykGB8dL5ogOY9KVyotiI4xT0deheAKn1HhzbXJK99I7J2XwB Vynqc/P6QAeQwnGw+irFSCr34U2CWTpgfDtKt8yw6ozsGga7i2hhL51ygMEJOEoi4Wz5 ZcgghUNL55KkFhWnpPqHhNVxIeY99Ab2nBeYeX4n4fJTkL6hMbKH8HdGGJhP7tVBrijU Kv3+BRbjREvdo308tlDbu9G4dPdHZ3xEBLLkgnr2gHCU22yvg9SuLZ1D3BFOKX2p1RnG lHjYbns9u6tj3QO5S5VIcx4BSdTX+Hz1YhnAA6c7ax37yTqkuNpMeGP9ivJXMhNP6zg0 6QbA== X-Gm-Message-State: APjAAAWmeFXmLBvLK+hisKSgT7wV08r5bmGwF9oiIDntRiKg0sjR+Iip CQruFKqOcVbbIfxUx7vNHXpGMMQp X-Google-Smtp-Source: APXvYqzhLx4HT6/iHXYY/lRbgzvswtQ8BpAwyny4yrxeVKhWIvSHhwsbr3b6fJNLMHfbnSj4C4QlJQ== X-Received: by 2002:ac2:4c82:: with SMTP id d2mr15617326lfl.62.1574864626598; Wed, 27 Nov 2019 06:23:46 -0800 (PST) Received: from seldlx21914.corpusers.net ([37.139.156.40]) by smtp.gmail.com with ESMTPSA id t8sm6975946lfl.51.2019.11.27.06.23.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 06:23:46 -0800 (PST) Date: Wed, 27 Nov 2019 15:23:45 +0100 From: Vitaly Wool To: , linux-kernel@vger.kernel.org Cc: Andrew Morton Subject: [PATCH 3/3] z3fold: protect handle reads Message-Id: <20191127152345.8059852f60947686674d726d@gmail.com> In-Reply-To: <20191127152012.17a4b35f9e7f6e50f9aaca9c@gmail.com> References: <20191127152012.17a4b35f9e7f6e50f9aaca9c@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; x86_64-unknown-linux-gnu) 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: We need to make sure slots are protected on reading a handle. Since handles are modified by free_handle() which only takes slot rwlock, that lock should be used when handles are read. Signed-off-by: Vitaly Wool --- mm/z3fold.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/z3fold.c b/mm/z3fold.c index f2a75418e248..43754d8ebce8 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -486,8 +486,12 @@ static unsigned long encode_handle(struct z3fold_header *zhdr, enum buddy bud) /* only for LAST bud, returns zero otherwise */ static unsigned short handle_to_chunks(unsigned long handle) { - unsigned long addr = *(unsigned long *)handle; + struct z3fold_buddy_slots *slots = handle_to_slots(handle); + unsigned long addr; + read_lock(&slots->lock); + addr = *(unsigned long *)handle; + read_unlock(&slots->lock); return (addr & ~PAGE_MASK) >> BUDDY_SHIFT; } @@ -499,10 +503,13 @@ static unsigned short handle_to_chunks(unsigned long handle) static enum buddy handle_to_buddy(unsigned long handle) { struct z3fold_header *zhdr; + struct z3fold_buddy_slots *slots = handle_to_slots(handle); unsigned long addr; + read_lock(&slots->lock); WARN_ON(handle & (1 << PAGE_HEADLESS)); addr = *(unsigned long *)handle; + read_unlock(&slots->lock); zhdr = (struct z3fold_header *)(addr & PAGE_MASK); return (addr - zhdr->first_num) & BUDDY_MASK; }