Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1229790ima; Wed, 24 Oct 2018 17:14:40 -0700 (PDT) X-Google-Smtp-Source: AJdET5dr3OG9G89JYHq4s9cwZZcHaF8y83cErxj7CTdRmE234Uvj5FXIeAgkGowYQeE2XemmRGtl X-Received: by 2002:a63:c14a:: with SMTP id p10-v6mr4498186pgi.424.1540426480207; Wed, 24 Oct 2018 17:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540426480; cv=none; d=google.com; s=arc-20160816; b=zQ47VcOWuSzzNfSqIin6hfRiT0NBbkDb2VOO7lTaRgVnr3idqNM4cO7ddybCvPhUrB G7hOczksPUTqzD7la46kdDrdkjLI2t52rYhWRNRCDvWVgcU8DVLhPaT70mHQNEHH5DFn Ir6sxSNbqjcgvPdi27deSGop4t5dAsukMyYf25Uvxb1bfA5wWtiJHD/asPs1vsXmX9Rw hp+33ZKQrCZ91e97ujBtYgnDbaw4VXdHJ9ZkjESW1D/hGro7dM5Ow2dVAepmCmWpDeQm ZzAQlr+LvIkqmCwFLnIK4Ml1E4G1FNdUi82okKipmxYIN+0pyqwu4yjLT1TQJbMSkm3X Ck6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=6Dz0CJy/5m7+uS7QA3MDg01ayJogASJH3CHbkaAtNKw=; b=qq4E6VLP05Eu2yJ+Tgtr8YPNAmuAbnq95rUMGCxjf3Vf5RriQweoEFePDBL1nrk8D6 wS63yjZCtSYOImkD2dtX6g6RQwGoCB6223QqAKGrctMvVrqwd+Qp5MXcozH2Eh2d0y9q z3LAbQOIvGgCboSAe88EOdezy1B4czEIEIWdKqwIQCTHFGTV2e58Nk/yy6D/Hw9+5/Ls rOPJlnGTxYjOjkY/9Nd45NCq6jrscYqLqzxgJWw2oKy6u/ek6fxfb6Su9JI/bBWDiZxL 3KYpy/nWqH8lGMOGnHy91PHqGKxiljHdm3cKGVRp/Oor0QBR/amoLx28zhbyUj7TLmGO h0lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Z6XM8dy+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f32-v6si5931590pgf.203.2018.10.24.17.14.23; Wed, 24 Oct 2018 17:14:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Z6XM8dy+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbeJYInl (ORCPT + 99 others); Thu, 25 Oct 2018 04:43:41 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:58872 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725829AbeJYInl (ORCPT ); Thu, 25 Oct 2018 04:43:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6Dz0CJy/5m7+uS7QA3MDg01ayJogASJH3CHbkaAtNKw=; b=Z6XM8dy+7o59O0wgwPXKr3rDT DRZveygxmqZfJVMU1fB2fXcFRnXnnwNw6XQ+16NUBI45rqW2WAJ7uFVNLbBywKJDN7f34fFWV111x aIWADb8CNuBUQzKdoQUOIGaFkWu8uI/LNy5qthqVrs2+Qz+xRShczF/QvuiL+QLrzvgqleLXWyWI8 TXt9vxzH6nX1Q9/uA6AMyrVln5fGCdb+1UlzGhKlXnabWG4N4g/GkPIMQMLvkIXVIdG6k0QcBDxzd qQS+F4QOOfr3Urnswjx0BCx+6pip5ZLbmRnVdf9l2bnd2HmqalysQlKud1+0yP78ALXQBLRAzdSaM xFGbJDnFw==; Received: from [167.98.65.38] (helo=worktop) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gFTH2-0001hf-Qq; Thu, 25 Oct 2018 00:13:17 +0000 Received: by worktop (Postfix, from userid 1000) id CC0816E0647; Thu, 25 Oct 2018 02:13:12 +0200 (CEST) Date: Thu, 25 Oct 2018 02:13:12 +0200 From: Peter Zijlstra To: Igor Stoppa Cc: Mimi Zohar , Kees Cook , Matthew Wilcox , Dave Chinner , James Morris , Michal Hocko , kernel-hardening@lists.openwall.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, igor.stoppa@huawei.com, Dave Hansen , Jonathan Corbet , Laura Abbott , Will Deacon , Boqun Feng , Arnd Bergmann , linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 16/17] prmem: pratomic-long Message-ID: <20181025001312.GA3159@worktop.c.hoisthospitality.com> References: <20181023213504.28905-1-igor.stoppa@huawei.com> <20181023213504.28905-17-igor.stoppa@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181023213504.28905-17-igor.stoppa@huawei.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 24, 2018 at 12:35:03AM +0300, Igor Stoppa wrote: > +static __always_inline > +bool __pratomic_long_op(bool inc, struct pratomic_long_t *l) > +{ > + struct page *page; > + uintptr_t base; > + uintptr_t offset; > + unsigned long flags; > + size_t size = sizeof(*l); > + bool is_virt = __is_wr_after_init(l, size); > + > + if (WARN(!(is_virt || likely(__is_wr_pool(l, size))), > + WR_ERR_RANGE_MSG)) > + return false; > + local_irq_save(flags); > + if (is_virt) > + page = virt_to_page(l); > + else > + vmalloc_to_page(l); > + offset = (~PAGE_MASK) & (uintptr_t)l; > + base = (uintptr_t)vmap(&page, 1, VM_MAP, PAGE_KERNEL); > + if (WARN(!base, WR_ERR_PAGE_MSG)) { > + local_irq_restore(flags); > + return false; > + } > + if (inc) > + atomic_long_inc((atomic_long_t *)(base + offset)); > + else > + atomic_long_dec((atomic_long_t *)(base + offset)); > + vunmap((void *)base); > + local_irq_restore(flags); > + return true; > + > +} That's just hideously nasty.. and horribly broken. We're not going to duplicate all these kernel interfaces wrapped in gunk like that. Also, you _cannot_ call vunmap() with IRQs disabled. Clearly you've never tested this with debug bits enabled.