All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: speck@linutronix.de
Subject: Re: [PATCH v4 7/8] L1TFv4 2
Date: Fri, 11 May 2018 10:23:05 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.21.1805110132450.2101@nanos.tec.linutronix.de> (raw)
In-Reply-To: <b31f6dd0e2447e3cbc0959209a946a5224d10499.1525900921.git.ak@linux.intel.com>

On Wed, 9 May 2018, speck for ak_at_linux.intel.com wrote:
  
> +static inline u64 maxpa_pfn_bit(int offset)

What is offset for? All callsites I found so far are handing in '1'.

Aside of that the function and the argument name are not really
intuitive. It suggests that it returns a bit number (at least that's how I
read it in the first place) with an address offset from the maximal
physical address while it returns the PFN of

    maximal physical address >> offset

> +{
> +	return BIT_ULL(boot_cpu_data.x86_phys_bits - offset - PAGE_SHIFT);
> +}

> +unsigned long max_swapfile_size(void)
> +{
> +	unsigned long pages;
> +
> +	pages = generic_max_swapfile_size();
> +
> +	if (boot_cpu_has(X86_BUG_L1TF)) {
> +		/* Limit the swap file size to MAX_PA/2 for L1TF workaround */
> +		pages = min_t(unsigned long, maxpa_pfn_bit(1), pages);

So here you use it for comparison as the maximum number of pages which fit
into MAX_PA/2. But in the next patch you use it to check whether the
returned bit mask is set in a pfn. 

> +/*
> +	if ((pfn & maxpa_pfn_bit(1)) && !capable(CAP_SYS_ADMIN))
> +		return false;

Both use cases are correct, but I had to look more than twice.

Aside of that returning u64 from that function is wrong. It works on 64 bit
but on 32bit 

    pages = min_t(unsigned long, maxpa_pfn_bit(1), pages);

will barf because unsigned long != u64.

I'd suggest to make it something like this:

static inline unsigned long l1tf_pfn_limit(void)
{
	return BIT_UL(boot_cpu_data.x86_phys_bits - offset - PAGE_SHIFT)  - 1;
}

and at the call sites then do:

	pages = min_t(unsigned long, l1tf_pfn_limit()  + 1, pages);

and

	if (pfn > l1tf_pnf_limit() && !capable(CAP_SYS_ADMIN))

which makes it obvious what that is about. 

Hmm?

Thanks,

	tglx

  reply	other threads:[~2018-05-11  8:23 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 21:25 [MODERATED] [PATCH v4 0/8] L1TFv4 0 ak
2018-05-09 21:25 ` [MODERATED] [PATCH v4 1/8] L1TFv4 1 ak
2018-05-10 23:00   ` Thomas Gleixner
2018-05-10 23:18     ` [MODERATED] " Andi Kleen
2018-05-09 21:25 ` [MODERATED] [PATCH v4 2/8] L1TFv4 4 ak
2018-05-09 21:25 ` [MODERATED] [PATCH v4 3/8] L1TFv4 6 ak
2018-05-10 23:15   ` Thomas Gleixner
2018-05-10 23:32     ` [MODERATED] " Andi Kleen
2018-05-10 23:41       ` Thomas Gleixner
2018-05-09 21:25 ` [MODERATED] [PATCH v4 4/8] L1TFv4 7 ak
2018-05-09 21:25 ` [MODERATED] [PATCH v4 5/8] L1TFv4 8 ak
2018-05-10 23:27   ` Thomas Gleixner
2018-05-09 21:25 ` [MODERATED] [PATCH v4 6/8] L1TFv4 3 ak
2018-05-10 22:52   ` Thomas Gleixner
2018-05-10 23:26     ` [MODERATED] " Andi Kleen
2018-05-10 23:46       ` Thomas Gleixner
2018-05-09 21:25 ` [MODERATED] [PATCH v4 7/8] L1TFv4 2 ak
2018-05-11  8:23   ` Thomas Gleixner [this message]
2018-05-11  8:24   ` Thomas Gleixner
2018-05-09 21:25 ` [MODERATED] [PATCH v4 8/8] L1TFv4 5 ak
2018-05-10  4:13   ` [MODERATED] " Andi Kleen
2018-05-09 21:54 ` [MODERATED] Re: [PATCH v4 0/8] L1TFv4 0 Andi Kleen
2018-05-10  6:47 ` [MODERATED] Re: ***UNCHECKED*** " Vlastimil Babka
2018-05-10  8:04   ` Michal Hocko
2018-05-10 16:07     ` Andi Kleen
2018-05-10 16:57       ` [MODERATED] " Borislav Petkov
2018-05-10 17:35         ` Andi Kleen
2018-05-10 22:11           ` Thomas Gleixner
2018-05-10 22:26             ` [MODERATED] " Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.21.1805110132450.2101@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=speck@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.