Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1264911ybl; Wed, 28 Aug 2019 12:01:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVpeLoxL9YCXVJ8I4MP5kLDPbkzLEphBkQmMoyGFb4Vs8tnIyG/J+lldQV1mKDBB/bMBTR X-Received: by 2002:a17:902:110b:: with SMTP id d11mr5970807pla.84.1567018869216; Wed, 28 Aug 2019 12:01:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567018869; cv=none; d=google.com; s=arc-20160816; b=KWcDMTpvx6AM/bLwtafiXN8UgtEvdCfR40GTD1m8UUhbMrWqtzpHZLbeEVDsXNWPRN oLerCR4j4DhQ53PTOFo5Qxj41tR0LnES9Gr1ZOwrynTRvmYiXUoxw7dgJAv7HcYlq014 XsTyc4Ng0reOfxWj0Dhu3387ZQQyV9awrsTE6jQz9JQgUuGxO7THGcgC901pBnht4UDM bWsryKIRObuuQGiqHE+Yrw+93rerG5Mo22x5RBqjcmMMaHU/xCRkF4ocntJmwzQl+wJU OASmdqdWSJtxD0zftRN4+v5aJ1AFoXKHEs439YbY6uNEctQP/7NfenPH4wfSjPybAX86 3BRA== 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=Rg266ysErRfz6Q6O8ZllDkT8j1Yu9RGIuCA6YHrmQ3E=; b=kAwVNQK1JalxQeF0quuHTGzfxCbCJ+S/fJ8p94TBYeEsck5tx28RP2zq5L/ujs9HGN lU0cvTRVBWPTy29F9Je6vFjrfl2gabs03ibPf7zeB2ZRmdJGLwldFgQS4Hyzs9rdacdZ YtdXPETkBZnYrs9yJlMO5Uoby1gIPDV2LNnzu6U3pu9EPKEgccuyQDiGG8nOuwRFRlj1 xgvG0lJhINLqtDXxDove/68docnSw+7P+YnUEgPreeXhicR6FwbUSDf4wZ5F0ikMPMR4 ygt/rpQ4VgW7oVgcyWt+KHtVOvahiqHwCFyWop5Jxc7eF+58C+dYd2FjT454fgZm5//v UmAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MUFabnk2; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o20si2913981pgc.503.2019.08.28.12.00.53; Wed, 28 Aug 2019 12:01:09 -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=@gmail.com header.s=20161025 header.b=MUFabnk2; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbfH1S6h (ORCPT + 99 others); Wed, 28 Aug 2019 14:58:37 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:35137 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbfH1S6g (ORCPT ); Wed, 28 Aug 2019 14:58:36 -0400 Received: by mail-wr1-f67.google.com with SMTP id g7so896957wrx.2 for ; Wed, 28 Aug 2019 11:58:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Rg266ysErRfz6Q6O8ZllDkT8j1Yu9RGIuCA6YHrmQ3E=; b=MUFabnk2H7YdNK5dqt8E6WFFJM/SNvgpRDY0fhZ7ln9Owbgr6VYnG30ClwbkprR8Ui wKeABdrdLQ21ZhDOX9wAW+uiNRqS/tiw4FPmeJ7DpIHl4bYKXvmuRyJhMn/3Nhug5Urd uDyDofZgEJEGvVexPuFc/c1Cnl669csAMi/k9OyhPzjG8cupcQ85nKx2Evxa1yigM8fU fF8WxyOGaO+zBYmLdGG+IZyu8qRLHcSqs4Yeu4/zS5eyzEiUJ3mD3rVs4W+s0lW/Jnz/ Dip87USG4/VB9tzICrUsCbSJRSco9+UV0p/dg0e3EXT6flb/W91heLtI0oD7qiyyxRdN My7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=Rg266ysErRfz6Q6O8ZllDkT8j1Yu9RGIuCA6YHrmQ3E=; b=MHawzNkbPZz4HlOdgkq2jWguBKei+AlyuN8E4T+qCxYZqXJus7GkR3105GyuWwlxZ1 C26if+8kfj+ACwxuMjGJQe5P+cNZzZE7bRTJo6lCaelo6FH1LehImXZkRlOTnepzVIyy jods1wwu5AUkweop2GNWyzoTRewri9ADGjoD5Whi6yh5kYy7lTsbaGux5Ij5VxvT5agh lCH23dgae1tl8Wk6a/vrkptCqR/fXArcxiYMqzSTNqJ+yDbrq3ywqJA7FgDYSVbWUIUc 1KwMDBH2AbdcfaNvduCL5l69lfyvDTDIdG0qqdnBIyA8SMF6Zr2OzOskToHM30Qx5IYi aeLg== X-Gm-Message-State: APjAAAWKFOEOpx/mXfsyPTGDEPVe3CD4TOd9WQ9MHZHJ8Sr8N59e30t5 26ARQ0XblGb+dSSDRspLla4= X-Received: by 2002:adf:ab18:: with SMTP id q24mr6027144wrc.354.1567018714860; Wed, 28 Aug 2019 11:58:34 -0700 (PDT) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id h125sm147104wmf.31.2019.08.28.11.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 11:58:34 -0700 (PDT) Date: Wed, 28 Aug 2019 20:58:32 +0200 From: Ingo Molnar To: Thomas Gleixner Cc: LKML , x86@kernel.org, Song Liu , Joerg Roedel , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Rik van Riel Subject: Re: [patch 1/2] x86/mm/pti: Handle unaligned address gracefully in pti_clone_pagetable() Message-ID: <20190828185832.GA77809@gmail.com> References: <20190828142445.454151604@linutronix.de> <20190828143123.971884723@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828143123.971884723@linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Thomas Gleixner wrote: > From: Song Liu > > pti_clone_pmds() assumes that the supplied address is either: > > - properly PUD/PMD aligned > or > - the address is actually mapped which means that independent > of the mapping level (PUD/PMD/PTE) the next higher mapping > exist. s/independent /independently s/exist /exists > If that's not the case the unaligned address can be incremented by PUD or > PMD size wrongly. All callers supply mapped and/or aligned addresses, but > for robustness sake, it's better to handle that case proper and to emit a > warning. s/wrongly /incorrectly s/robustness sake /robustness's sake s/proper /properly With that: > pud = pud_offset(p4d, addr); > if (pud_none(*pud)) { > - addr += PUD_SIZE; > + WARN_ON_ONCE(addr & PUD_MASK); > + addr = round_up(addr + 1, PUD_SIZE); > continue; > } > > pmd = pmd_offset(pud, addr); > if (pmd_none(*pmd)) { > - addr += PMD_SIZE; > + WARN_ON_ONCE(addr & PMD_MASK); > + addr = round_up(addr + 1, PMD_SIZE); So given that PUD_MASK and PMD_MASK are masking out the *offset*: arch/x86/include/asm/pgtable_64_types.h:#define PMD_MASK (~(PMD_SIZE - 1)) Didn't we want something like: WARN_ON_ONCE(addr & ~PUD_MASK); WARN_ON_ONCE(addr & ~PMD_MASK); to warn about an unaligned 'addr', or am I misreading the intent here? Thanks, Ingo